Date rendering fixes
gitea/hedera-web/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2021-01-23 17:15:02 +01:00
parent b09e345e62
commit 6a040cd4d8
5 changed files with 35 additions and 15 deletions

2
debian/changelog vendored
View File

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

View File

@ -8,7 +8,7 @@
* Warning! You should set a well defined dababase level privileges to use this
* class or you could have a serious security hole in you application becasuse
* the user can send any statement to the server. For example: DROP DATABASE
**/
*/
var Connection = new Class();
module.exports = Connection;
@ -42,7 +42,7 @@ Connection.implement({
*
* @param {String} sql The SQL statement
* @param {Function} callback The function to call when operation is done
**/
*/
,execSql: function(sql, callback) {
this.send('core/query', {'sql': sql},
this._onExec.bind(this, callback));
@ -54,7 +54,7 @@ Connection.implement({
* @param {Sql.Stmt} stmt The statement
* @param {Function} callback The function to call when operation is done
* @param {Sql.Batch} batch The batch used to set the parameters
**/
*/
,execStmt: function(stmt, callback, batch) {
this.execSql(stmt.render(batch), callback);
}
@ -65,7 +65,7 @@ Connection.implement({
* @param {String} query The SQL statement
* @param {Function} callback The function to call when operation is done
* @param {Sql.Batch} batch The batch used to set the parameters
**/
*/
,execQuery: function(query, callback, batch) {
this.execStmt(new Sql.String({query: query}), callback, batch);
}

View File

@ -91,19 +91,37 @@ module.exports = new Class({
case 'string':
return "'" + v.replace(this.regexp, this.replaceFunc) + "'";
default:
if (v instanceof Date)
return Vn.Date.strftime(fixTz(v), '\'%Y-%m-%d\'');
else
if (v instanceof Date) {
if (!isNaN(v.getTime())) {
var unixTime = parseInt(fixTz(v).getTime() / 1000);
return 'DATE(FROM_UNIXTIME('+ unixTime +'))';
} else
return '0000-00-00'
} 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'};
var isLocal = Intl
.DateTimeFormat()
.resolvedOptions()
.timeZone == tz.timeZone;
// TODO: Read time zone from db configuration
var tz = {timeZone: 'Europe/Madrid'};
return new Date(midDay.toLocaleString('en-US', tz));
function fixTz(date) {
if (isLocal) return date;
var hasTime = date.getHours()
|| date.getMinutes()
|| date.getSeconds()
|| date.getMilliseconds();
if (!hasTime) {
date = new Date(date.getTime());
date.setHours(12, 0, 0, 0);
}
return date;
}

View File

@ -117,6 +117,8 @@ module.exports =
return '';
if (!(date instanceof Date))
date = new Date(date);
if (isNaN(date.getTime()))
return date.toString();
return format.replace(this.regexp, this.regexpFunc.bind(this, date));
}

View File

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