removed a chrome/node/nw date hack... still not final

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-04-11 15:58:12 +03:00
parent f627483322
commit 8982365b03
2 changed files with 89 additions and 69 deletions

View File

@ -60,13 +60,23 @@ if(typeof(process) != 'undefined'){
// NOTE: jli is patching the Date object and with two separate
// instances we'll need to sync things up...
// XXX HACK...
global.Date !== window.Date
&& global.Date = window.Date
// XXX HACK: if node and chrome Date implementations ever
// significantly diverge this will break things + this is
// a potential data leak between contexts...
//global.Date = window.Date
// XXX this is less of a hack but it is still an implicit
patchDate(global.Date)
patchDate(window.Date)
// node...
} else {
ImageGridFeatures.runtime = 'node'
// XXX patch Date...
// XXX this will not work directly as we will need to explicitly
// require jli...
//patchDate(global.Date)
}
// browser...

View File

@ -1055,7 +1055,12 @@ var cancelAnimationFrame = (window.cancelRequestAnimationFrame
|| clearTimeout)
Date.prototype.toShortDate = function(){
// NOTE: repatching a date should not lead to any side effects as this
// does not add any state...
function patchDate(date){
date = date || Date
date.prototype.toShortDate = function(){
var y = this.getFullYear()
var M = this.getMonth()+1
M = M < 10 ? '0'+M : M
@ -1070,7 +1075,7 @@ Date.prototype.toShortDate = function(){
return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s
}
Date.prototype.getTimeStamp = function(no_seconds){
date.prototype.getTimeStamp = function(no_seconds){
var y = this.getFullYear()
var M = this.getMonth()+1
M = M < 10 ? '0'+M : M
@ -1085,7 +1090,7 @@ Date.prototype.getTimeStamp = function(no_seconds){
return ''+y+M+D+H+m+s
}
Date.prototype.setTimeStamp = function(ts){
date.prototype.setTimeStamp = function(ts){
ts = ts.replace(/[^0-9]*/g, '')
this.setFullYear(ts.slice(0, 4))
this.setMonth(ts.slice(4, 6)*1-1)
@ -1095,14 +1100,14 @@ Date.prototype.setTimeStamp = function(ts){
this.setSeconds(ts.slice(12, 14))
return this
}
Date.timeStamp = function(){
return (new Date()).getTimeStamp()
date.timeStamp = function(){
return (new this()).getTimeStamp()
}
Date.fromTimeStamp = function(ts){
return (new Date()).setTimeStamp(ts)
date.fromTimeStamp = function(ts){
return (new this()).setTimeStamp(ts)
}
// convert string time period to milliseconds...
Date.str2ms = function(str, dfl){
date.str2ms = function(str, dfl){
dfl = dfl || 'ms'
if(typeof(str) == typeof(123)){
@ -1127,6 +1132,11 @@ Date.str2ms = function(str, dfl){
return c ? val * c : NaN
}
return date
}
// patch the root date...
patchDate()
function logCalls(func, logger){
var that = this