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 // NOTE: jli is patching the Date object and with two separate
// instances we'll need to sync things up... // instances we'll need to sync things up...
// XXX HACK... // XXX HACK: if node and chrome Date implementations ever
global.Date !== window.Date // significantly diverge this will break things + this is
&& global.Date = window.Date // 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... // node...
} else { } else {
ImageGridFeatures.runtime = 'node' ImageGridFeatures.runtime = 'node'
// XXX patch Date...
// XXX this will not work directly as we will need to explicitly
// require jli...
//patchDate(global.Date)
} }
// browser... // browser...

View File

@ -1055,77 +1055,87 @@ var cancelAnimationFrame = (window.cancelRequestAnimationFrame
|| clearTimeout) || clearTimeout)
Date.prototype.toShortDate = function(){ // NOTE: repatching a date should not lead to any side effects as this
var y = this.getFullYear() // does not add any state...
var M = this.getMonth()+1 function patchDate(date){
M = M < 10 ? '0'+M : M date = date || Date
var D = this.getDate()
D = D < 10 ? '0'+D : D
var H = this.getHours()
H = H < 10 ? '0'+H : H
var m = this.getMinutes()
m = m < 10 ? '0'+m : m
var s = this.getSeconds()
s = s < 10 ? '0'+s : s
return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s date.prototype.toShortDate = function(){
} var y = this.getFullYear()
Date.prototype.getTimeStamp = function(no_seconds){ var M = this.getMonth()+1
var y = this.getFullYear() M = M < 10 ? '0'+M : M
var M = this.getMonth()+1 var D = this.getDate()
M = M < 10 ? '0'+M : M D = D < 10 ? '0'+D : D
var D = this.getDate() var H = this.getHours()
D = D < 10 ? '0'+D : D H = H < 10 ? '0'+H : H
var H = this.getHours() var m = this.getMinutes()
H = H < 10 ? '0'+H : H m = m < 10 ? '0'+m : m
var m = this.getMinutes() var s = this.getSeconds()
m = m < 10 ? '0'+m : m s = s < 10 ? '0'+s : s
var s = this.getSeconds()
s = s < 10 ? '0'+s : s
return ''+y+M+D+H+m+s return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s
}
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)
this.setDate(ts.slice(6, 8))
this.setHours(ts.slice(8, 10))
this.setMinutes(ts.slice(10, 12))
this.setSeconds(ts.slice(12, 14))
return this
}
Date.timeStamp = function(){
return (new Date()).getTimeStamp()
}
Date.fromTimeStamp = function(ts){
return (new Date()).setTimeStamp(ts)
}
// convert string time period to milliseconds...
Date.str2ms = function(str, dfl){
dfl = dfl || 'ms'
if(typeof(str) == typeof(123)){
var val = str
str = dfl
} else {
var val = parseFloat(str)
str = str.trim()
// check if a unit is given...
str = str == val ? dfl : str
} }
date.prototype.getTimeStamp = function(no_seconds){
var c = /(m(illi)?(-)?s(ec(ond(s)?)?)?)$/i.test(str) ? 1 var y = this.getFullYear()
: /s(ec(ond(s)?)?)?$/i.test(str) ? 1000 var M = this.getMonth()+1
: /m(in(ute(s)?)?)?$/i.test(str) ? 1000*60 M = M < 10 ? '0'+M : M
: /h(our(s)?)?$/i.test(str) ? 1000*60*60 var D = this.getDate()
: /d(ay(s)?)?$/i.test(str) ? 1000*60*60*24 D = D < 10 ? '0'+D : D
: null var H = this.getHours()
H = H < 10 ? '0'+H : H
var m = this.getMinutes()
m = m < 10 ? '0'+m : m
var s = this.getSeconds()
s = s < 10 ? '0'+s : s
return c ? val * c : NaN return ''+y+M+D+H+m+s
}
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)
this.setDate(ts.slice(6, 8))
this.setHours(ts.slice(8, 10))
this.setMinutes(ts.slice(10, 12))
this.setSeconds(ts.slice(12, 14))
return this
}
date.timeStamp = function(){
return (new this()).getTimeStamp()
}
date.fromTimeStamp = function(ts){
return (new this()).setTimeStamp(ts)
}
// convert string time period to milliseconds...
date.str2ms = function(str, dfl){
dfl = dfl || 'ms'
if(typeof(str) == typeof(123)){
var val = str
str = dfl
} else {
var val = parseFloat(str)
str = str.trim()
// check if a unit is given...
str = str == val ? dfl : str
}
var c = /(m(illi)?(-)?s(ec(ond(s)?)?)?)$/i.test(str) ? 1
: /s(ec(ond(s)?)?)?$/i.test(str) ? 1000
: /m(in(ute(s)?)?)?$/i.test(str) ? 1000*60
: /h(our(s)?)?$/i.test(str) ? 1000*60*60
: /d(ay(s)?)?$/i.test(str) ? 1000*60*60*24
: null
return c ? val * c : NaN
}
return date
} }
// patch the root date...
patchDate()
function logCalls(func, logger){ function logCalls(func, logger){