0
1
Fork 0

Timezone fixes

This commit is contained in:
Juan Ferrer 2020-05-04 21:55:18 +02:00
parent 7219962f0c
commit 54966582b5
8 changed files with 184 additions and 174 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.407.12) stable; urgency=low hedera-web (1.407.13) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -27,6 +27,8 @@ Hedera.Checkout = new Class({
if (!date || date.getTime() < (new Date()).getTime()) { if (!date || date.getTime() < (new Date()).getTime()) {
date = new Date(); date = new Date();
date.setHours(0, 0, 0, 0);
var addDays = 0; var addDays = 0;
switch(date.getDay()) { switch(date.getDay()) {
@ -41,7 +43,7 @@ Hedera.Checkout = new Class({
if (i.get('deliveryMethod') != 'PICKUP') if (i.get('deliveryMethod') != 'PICKUP')
addDays++; addDays++;
date.setTime(date.getTime() + addDays * 86400000); date.setDate(date.getDate() + addDays);
} }
this.$('date').value = date; this.$('date').value = date;

View File

@ -29,14 +29,12 @@ var Type =
,DATE_TIME : 9 ,DATE_TIME : 9
}; };
Connection.extend Connection.extend({
({
Flag: Flag Flag: Flag
,Type: Type ,Type: Type
}); });
Connection.implement Connection.implement({
({
Extends: Vn.JsonConnection Extends: Vn.JsonConnection
/** /**
@ -76,7 +74,7 @@ Connection.implement
* Parses a value to date. * Parses a value to date.
*/ */
,valueToDate: function(value) { ,valueToDate: function(value) {
return new Date(value); return fixTz(new Date(value));
} }
/* /*
@ -121,3 +119,26 @@ Connection.implement
} }
}); });
// TODO: Read time zone from db configuration
var tz = {timeZone: 'Europe/Madrid'};
var isLocal = Intl
.DateTimeFormat()
.resolvedOptions()
.timeZone == tz.timeZone;
function fixTz(date) {
if (isLocal) return date;
var localDate = new Date(date.toLocaleString('en-US', tz));
var hasTime = localDate.getHours()
|| localDate.getMinutes()
|| localDate.getSeconds()
|| localDate.getMilliseconds();
if (!hasTime) {
date.setHours(date.getHours() + 12);
date.setHours(0, 0, 0, 0);
}
return date;
}

View File

@ -1,6 +1,5 @@
module.exports = new Class module.exports = new Class({
({
Extends: Htk.Field Extends: Htk.Field
,Tag: 'htk-calendar' ,Tag: 'htk-calendar'
,Properties: ,Properties:
@ -8,12 +7,10 @@ module.exports = new Class
restrictFunc: restrictFunc:
{ {
type: Function type: Function
,set: function (x) ,set: function(x) {
{
this._restrictFunc = x; this._restrictFunc = x;
} }
,get: function (x) ,get: function(x) {
{
return this._restrictFunc; return this._restrictFunc;
} }
} }
@ -24,8 +21,7 @@ module.exports = new Class
,year: null ,year: null
,month: null ,month: null
,render: function () ,render: function() {
{
var len = Vn.Date.WDays.length; var len = Vn.Date.WDays.length;
var node = this.createRoot('div'); var node = this.createRoot('div');
@ -74,8 +70,7 @@ module.exports = new Class
var tr = this.createElement('tr'); var tr = this.createElement('tr');
thead.appendChild(tr); thead.appendChild(tr);
for (var i = 1; i <= len; i++) for (var i = 1; i <= len; i++) {
{
var th = this.createElement('th'); var th = this.createElement('th');
tr.appendChild(th); tr.appendChild(th);
@ -86,13 +81,11 @@ module.exports = new Class
var tbody = this.createElement('tbody'); var tbody = this.createElement('tbody');
table.appendChild(tbody); table.appendChild(tbody);
for (var i = 0; i < 6; i++) for (var i = 0; i < 6; i++) {
{
var tr = this.createElement('tr'); var tr = this.createElement('tr');
tbody.appendChild(tr); tbody.appendChild(tr);
for (var j = 0; j < len; j++) for (var j = 0; j < len; j++) {
{
var td = this.createElement('td'); var td = this.createElement('td');
td.addEventListener('click', this.dayClicked.bind(this, td, i*len+j)); td.addEventListener('click', this.dayClicked.bind(this, td, i*len+j));
tr.appendChild(td); tr.appendChild(td);
@ -113,8 +106,7 @@ module.exports = new Class
this.goToCurrentMonth(); this.goToCurrentMonth();
} }
,getMonthDays: function () ,getMonthDays: function() {
{
if (this.month > 6) if (this.month > 6)
return (this.month % 2 != 0) ? 31 : 30; return (this.month % 2 != 0) ? 31 : 30;
else if (this.month != 1) else if (this.month != 1)
@ -123,8 +115,7 @@ module.exports = new Class
return (this.year % 4 != 0) ? 28 : 29; return (this.year % 4 != 0) ? 28 : 29;
} }
,goToMonth: function (year, month) ,goToMonth: function(year, month) {
{
if (year) if (year)
this.year = year; this.year = year;
if (!isNaN(month)) if (!isNaN(month))
@ -133,8 +124,7 @@ module.exports = new Class
this.refresh(); this.refresh();
} }
,goToSelectedMonth: function () ,goToSelectedMonth: function() {
{
var date = this._value; var date = this._value;
if (date instanceof Date) if (date instanceof Date)
@ -143,14 +133,12 @@ module.exports = new Class
this.goToCurrentMonth(); this.goToCurrentMonth();
} }
,goToCurrentMonth: function () ,goToCurrentMonth: function() {
{
var date = new Date(); var date = new Date();
this.goToMonth(date.getFullYear(), date.getMonth()); this.goToMonth(date.getFullYear(), date.getMonth());
} }
,refresh: function () ,refresh: function() {
{
Vn.Node.setText(this.yearNode, this.year); Vn.Node.setText(this.yearNode, this.year);
Vn.Node.setText(this.monthNode, _(Vn.Date.Months[this.month])); Vn.Node.setText(this.monthNode, _(Vn.Date.Months[this.month]));
@ -161,24 +149,19 @@ module.exports = new Class
var firstWeekDay = (weekDay != 0) ? weekDay - 1 : 6; var firstWeekDay = (weekDay != 0) ? weekDay - 1 : 6;
var monthDays = this.getMonthDays(); var monthDays = this.getMonthDays();
for (var i = 0; i < this.cells.length; i++) for (var i = 0; i < this.cells.length; i++) {
{
var cell = this.cells[i]; var cell = this.cells[i];
if (firstWeekDay <= i && day <= monthDays) if (firstWeekDay <= i && day <= monthDays) {
{
Vn.Node.setText(cell.node, day); Vn.Node.setText(cell.node, day);
cell.enabled = true; cell.enabled = true;
cell.day = day++; cell.day = day++;
if (this._restrictFunc) if (this._restrictFunc) {
{
cell.enabled = this._restrictFunc(cellDate); cell.enabled = this._restrictFunc(cellDate);
cellDate.setDate(cellDate.getDate() + 1); cellDate.setDate(cellDate.getDate() + 1);
} }
} } else {
else
{
Vn.Node.removeChilds(cell.node); Vn.Node.removeChilds(cell.node);
cell.enabled = false; cell.enabled = false;
cell.day = -1; cell.day = -1;
@ -192,8 +175,7 @@ module.exports = new Class
var today = new Date(); var today = new Date();
if (this.year == today.getFullYear() if (this.year == today.getFullYear()
&& this.month == today.getMonth ()) && this.month == today.getMonth()) {
{
var cellIndex = (firstWeekDay + today.getDate()) - 1; var cellIndex = (firstWeekDay + today.getDate()) - 1;
Vn.Node.addClass(this.cells[cellIndex].node, 'today'); Vn.Node.addClass(this.cells[cellIndex].node, 'today');
} }
@ -210,15 +192,12 @@ module.exports = new Class
this.selectCell(-1); this.selectCell(-1);
} }
,selectCell: function (cellIndex) ,selectCell: function(cellIndex) {
{ if (this.selectedCell != -1) {
if (this.selectedCell != -1)
{
var node = this.cells[this.selectedCell].node; var node = this.cells[this.selectedCell].node;
Vn.Node.removeClass(node, 'selected'); Vn.Node.removeClass(node, 'selected');
} }
if (cellIndex != -1) if (cellIndex != -1) {
{
var node = this.cells[cellIndex].node; var node = this.cells[cellIndex].node;
Vn.Node.addClass(node, 'selected'); Vn.Node.addClass(node, 'selected');
} }
@ -226,30 +205,39 @@ module.exports = new Class
this.selectedCell = cellIndex; this.selectedCell = cellIndex;
} }
,putValue: function (value) ,putValue: function() {
{
this.goToSelectedMonth(); this.goToSelectedMonth();
} }
,dayClicked: function (td, cellIndex) ,dayClicked: function(td, cellIndex) {
{
var cell = this.cells[cellIndex]; var cell = this.cells[cellIndex];
if (cell.enabled) if (cell.enabled) {
{
this.selectCell(cellIndex); this.selectCell(cellIndex);
var newDate = new Date(this.year, this.month, cell.day); var newDate = new Date(this.year, this.month, cell.day);
if (this.value) {
var orgDate = this.value instanceof Date
? this.value
: new Date(this.value);
newDate.setHours(
orgDate.getHours(),
orgDate.getMinutes(),
orgDate.getSeconds(),
orgDate.getMilliseconds()
);
}
this.valueChanged(newDate); this.valueChanged(newDate);
} }
} }
,prevMonthClicked: function () ,prevMonthClicked: function() {
{
if (this.month > 0) if (this.month > 0)
this.month--; this.month--;
else else {
{
this.month = 11; this.month = 11;
this.year--; this.year--;
} }
@ -257,12 +245,10 @@ module.exports = new Class
this.refresh(); this.refresh();
} }
,nextMonthClicked: function () ,nextMonthClicked: function() {
{
if (this.month < 11) if (this.month < 11)
this.month++; this.month++;
else else {
{
this.month = 0; this.month = 0;
this.year++; this.year++;
} }

View File

@ -91,14 +91,19 @@ module.exports = new Class({
case 'string': case 'string':
return "'" + v.replace(this.regexp, this.replaceFunc) + "'"; return "'" + v.replace(this.regexp, this.replaceFunc) + "'";
default: default:
if (v instanceof Date) { if (v instanceof Date)
// TODO: Read time zone from db configuration return Vn.Date.strftime(fixTz(v), '\'%Y-%m-%d\'');
var tz = {timeZone: 'Europe/Madrid'}; else
var localeDate = new Date(v.toLocaleString('en-US', tz));
return Vn.Date.strftime(localeDate, '\'%Y-%m-%d\'');
} else {
return 'NULL'; return 'NULL';
} }
} }
}
}); });
function fixTz(date) {
var midDay = new Date(date.getTime());
midDay.setHours(12, 0, 0, 0);
// TODO: Read time zone from db configuration
var tz = {timeZone: 'Europe/Madrid'};
return new Date(midDay.toLocaleString('en-US', tz));
}

View File

@ -2,8 +2,7 @@
* Date handling utilities. * Date handling utilities.
**/ **/
Date.prototype.clone = function () Date.prototype.clone = function() {
{
return new Date(this.getTime()); return new Date(this.getTime());
} }
@ -64,18 +63,15 @@ module.exports =
,regexp: new RegExp('%[a-zA-Z]', 'g') ,regexp: new RegExp('%[a-zA-Z]', 'g')
,pad: function (number) ,pad: function(number) {
{
if (number < 10) if (number < 10)
return '0'+ number.toString(); return '0'+ number.toString();
return number.toString(); return number.toString();
} }
,regexpFunc: function (d, token) ,regexpFunc: function(d, token) {
{ switch (token.charAt(1)) {
switch (token.charAt (1))
{
// Minutes with 2 digits // Minutes with 2 digits
case 'M': return this.pad(d.getMinutes()); case 'M': return this.pad(d.getMinutes());
@ -116,12 +112,12 @@ module.exports =
return token; return token;
} }
,strftime: function (date, format) ,strftime: function(date, format) {
{
if (!date) if (!date)
return ''; return '';
if (!(date instanceof Date))
date = new Date(date);
return format.replace(this.regexp, this.regexpFunc.bind(this, date)); return format.replace(this.regexp, this.regexpFunc.bind(this, date));
} }
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "hedera-web", "name": "hedera-web",
"version": "1.407.12", "version": "1.407.13",
"description": "Verdnatura web page", "description": "Verdnatura web page",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

View File

@ -163,10 +163,10 @@ class Query extends Vn\Web\JsonRequest {
* Transforms the database value into a JSON parseable value. * Transforms the database value into a JSON parseable value.
**/ **/
function castValue($value, $type) { function castValue($value, $type) {
if ($value == '' && $type != Type::STRING) if ($value === '' && $type != Type::STRING)
$value = NULL; $value = NULL;
if (!empty($value)) if ($value !== NULL)
switch ($type) { switch ($type) {
case Type::BOOLEAN: case Type::BOOLEAN:
return (bool) $value; return (bool) $value;