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.

View File

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

View File

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

View File

@ -91,14 +91,19 @@ module.exports = new Class({
case 'string':
return "'" + v.replace(this.regexp, this.replaceFunc) + "'";
default:
if (v instanceof Date) {
// TODO: Read time zone from db configuration
var tz = {timeZone: 'Europe/Madrid'};
var localeDate = new Date(v.toLocaleString('en-US', tz));
return Vn.Date.strftime(localeDate, '\'%Y-%m-%d\'');
} else {
if (v instanceof Date)
return Vn.Date.strftime(fixTz(v), '\'%Y-%m-%d\'');
else
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.prototype.clone = function ()
{
Date.prototype.clone = function() {
return new Date(this.getTime());
}
@ -64,18 +63,15 @@ module.exports =
,regexp: new RegExp('%[a-zA-Z]', 'g')
,pad: function (number)
{
,pad: function(number) {
if (number < 10)
return '0'+ number.toString();
return number.toString();
}
,regexpFunc: function (d, token)
{
switch (token.charAt (1))
{
,regexpFunc: function(d, token) {
switch (token.charAt(1)) {
// Minutes with 2 digits
case 'M': return this.pad(d.getMinutes());
@ -116,12 +112,12 @@ module.exports =
return token;
}
,strftime: function (date, format)
{
,strftime: function(date, format) {
if (!date)
return '';
if (!(date instanceof Date))
date = new Date(date);
return format.replace(this.regexp, this.regexpFunc.bind(this, date));
}
};

View File

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

View File

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