forked from verdnatura/hedera-web
Date rendering fixes
This commit is contained in:
parent
b09e345e62
commit
6a040cd4d8
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.407.38) stable; urgency=low
|
hedera-web (1.407.39) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* Warning! You should set a well defined dababase level privileges to use this
|
* 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
|
* 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
|
* the user can send any statement to the server. For example: DROP DATABASE
|
||||||
**/
|
*/
|
||||||
var Connection = new Class();
|
var Connection = new Class();
|
||||||
module.exports = Connection;
|
module.exports = Connection;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ Connection.implement({
|
||||||
*
|
*
|
||||||
* @param {String} sql The SQL statement
|
* @param {String} sql The SQL statement
|
||||||
* @param {Function} callback The function to call when operation is done
|
* @param {Function} callback The function to call when operation is done
|
||||||
**/
|
*/
|
||||||
,execSql: function(sql, callback) {
|
,execSql: function(sql, callback) {
|
||||||
this.send('core/query', {'sql': sql},
|
this.send('core/query', {'sql': sql},
|
||||||
this._onExec.bind(this, callback));
|
this._onExec.bind(this, callback));
|
||||||
|
@ -54,7 +54,7 @@ Connection.implement({
|
||||||
* @param {Sql.Stmt} stmt The statement
|
* @param {Sql.Stmt} stmt The statement
|
||||||
* @param {Function} callback The function to call when operation is done
|
* @param {Function} callback The function to call when operation is done
|
||||||
* @param {Sql.Batch} batch The batch used to set the parameters
|
* @param {Sql.Batch} batch The batch used to set the parameters
|
||||||
**/
|
*/
|
||||||
,execStmt: function(stmt, callback, batch) {
|
,execStmt: function(stmt, callback, batch) {
|
||||||
this.execSql(stmt.render(batch), callback);
|
this.execSql(stmt.render(batch), callback);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ Connection.implement({
|
||||||
* @param {String} query The SQL statement
|
* @param {String} query The SQL statement
|
||||||
* @param {Function} callback The function to call when operation is done
|
* @param {Function} callback The function to call when operation is done
|
||||||
* @param {Sql.Batch} batch The batch used to set the parameters
|
* @param {Sql.Batch} batch The batch used to set the parameters
|
||||||
**/
|
*/
|
||||||
,execQuery: function(query, callback, batch) {
|
,execQuery: function(query, callback, batch) {
|
||||||
this.execStmt(new Sql.String({query: query}), callback, batch);
|
this.execStmt(new Sql.String({query: query}), callback, batch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,19 +91,37 @@ 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) {
|
||||||
return Vn.Date.strftime(fixTz(v), '\'%Y-%m-%d\'');
|
if (!isNaN(v.getTime())) {
|
||||||
else
|
var unixTime = parseInt(fixTz(v).getTime() / 1000);
|
||||||
|
return 'DATE(FROM_UNIXTIME('+ unixTime +'))';
|
||||||
|
} else
|
||||||
|
return '0000-00-00'
|
||||||
|
} else
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function fixTz(date) {
|
// TODO: Read time zone from db configuration
|
||||||
var midDay = new Date(date.getTime());
|
var tz = {timeZone: 'Europe/Madrid'};
|
||||||
midDay.setHours(12, 0, 0, 0);
|
var isLocal = Intl
|
||||||
|
.DateTimeFormat()
|
||||||
|
.resolvedOptions()
|
||||||
|
.timeZone == tz.timeZone;
|
||||||
|
|
||||||
// TODO: Read time zone from db configuration
|
function fixTz(date) {
|
||||||
var tz = {timeZone: 'Europe/Madrid'};
|
if (isLocal) return date;
|
||||||
return new Date(midDay.toLocaleString('en-US', tz));
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,8 @@ module.exports =
|
||||||
return '';
|
return '';
|
||||||
if (!(date instanceof Date))
|
if (!(date instanceof Date))
|
||||||
date = new Date(date);
|
date = new Date(date);
|
||||||
|
if (isNaN(date.getTime()))
|
||||||
|
return date.toString();
|
||||||
|
|
||||||
return format.replace(this.regexp, this.regexpFunc.bind(this, date));
|
return format.replace(this.regexp, this.regexpFunc.bind(this, date));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hedera-web",
|
"name": "hedera-web",
|
||||||
"version": "1.407.38",
|
"version": "1.407.39",
|
||||||
"description": "Verdnatura web page",
|
"description": "Verdnatura web page",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
Loading…
Reference in New Issue