From 8982365b035f5f047fb414a4569d79143a0cfeae Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 11 Apr 2016 15:58:12 +0300 Subject: [PATCH] removed a chrome/node/nw date hack... still not final Signed-off-by: Alex A. Naanou --- ui (gen4)/features/core.js | 16 ++++- ui (gen4)/lib/jli.js | 142 ++++++++++++++++++++----------------- 2 files changed, 89 insertions(+), 69 deletions(-) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index e6e0521c..462d514b 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -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... diff --git a/ui (gen4)/lib/jli.js b/ui (gen4)/lib/jli.js index 4c183f7d..b29472b8 100755 --- a/ui (gen4)/lib/jli.js +++ b/ui (gen4)/lib/jli.js @@ -1055,77 +1055,87 @@ var cancelAnimationFrame = (window.cancelRequestAnimationFrame || clearTimeout) -Date.prototype.toShortDate = function(){ - var y = this.getFullYear() - var M = this.getMonth()+1 - M = M < 10 ? '0'+M : M - 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 +// NOTE: repatching a date should not lead to any side effects as this +// does not add any state... +function patchDate(date){ + date = date || Date - return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s -} -Date.prototype.getTimeStamp = function(no_seconds){ - var y = this.getFullYear() - var M = this.getMonth()+1 - M = M < 10 ? '0'+M : M - 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 + date.prototype.toShortDate = function(){ + var y = this.getFullYear() + var M = this.getMonth()+1 + M = M < 10 ? '0'+M : M + 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.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 + return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s } - - 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 + date.prototype.getTimeStamp = function(no_seconds){ + var y = this.getFullYear() + var M = this.getMonth()+1 + M = M < 10 ? '0'+M : M + 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 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){