Dates with Timezones and ISO8601 Date Constants.
Are you familiar with the Temporal proposal? tc39/proposal
Are you familiar with the Temporal proposal? https://github.com/tc39/proposal-temporal On Mon, Sep 24, 2018 at 8:32 PM, J Decker <d3ck0r at gmail.com> wrote: > I did look back to see other conversations about Dates.... > > Operating with arbitrary timezones > https://mail.mozilla.org/pipermail/es-discuss/2016-August/046478.html > > Add timezone data to Date > https://mail.mozilla.org/pipermail/es-discuss/2017-June/048259.html > > Even until this moment, Edge/IE cannot parse new Date( > "2018-09-25T00:17:55.385-07:00"). which makes 50% of the world already > require a date/time library. > https://github.com/Microsoft/ChakraCore/issues/5502 > (actually Aug 16 that was closed) > > Date.toISOString() only emits 'Z', even though the type itself has the > offset > > as a Date.prototype.toISOLocalString() > cb : function () { > var tzo = -this.getTimezoneOffset(), > dif = tzo >= 0 ? '+' : '-', > pad = function(num) { > var norm = Math.floor(Math.abs(num)); > return (norm < 10 ? '0' : '') + norm; > }; > return this.getFullYear() + > '-' + pad(this.getMonth() + 1) + > '-' + pad(this.getDate()) + > 'T' + pad(this.getHours()) + > ':' + pad(this.getMinutes()) + > ':' + pad(this.getSeconds()) + > dif + pad(tzo / 60) + > ':' + pad(tzo % 60); > } > ---------- > But; that's only semi-accurate, because if I say -07:00 as the offset, I > don't know if it's MST or PDT (which is knowable I suppose). > > There's not a LOT of usage of times in code; but it could be that the > constant number 2018-09-25T00:26:00.741Z could just BE a Date, similar to > 123n just being a BigInt. > > It would also be handy if there were a builtin ISO w/ Timezone emitter. > > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180924/661d7ae6/attachment.html>
That's a little like using a sledge hammer to cut cake.
Adding Dates as a type of data in JSOX, the additional rule to handle dates in the parser is pretty simple. raw.githubusercontent.com/d3x0r/JSOX/master/NumberRule.GIF
I'm also not sure it's really needed to know if it was ' MST or PDT ' at that time. With whatever the current offset was at that time, that's the time it was for them (or the time they claim is for them), and the time it was relative to everyone else.
That's a little like using a sledge hammer to cut cake. Adding Dates as a type of data in JSOX, the additional rule to handle dates in the parser is pretty simple. https://raw.githubusercontent.com/d3x0r/JSOX/master/NumberRule.GIF I'm also not sure it's really needed to know if it was ' MST or PDT ' at that time. With whatever the current offset was at that time, that's the time it was for them (or the time they claim is for them), and the time it was relative to everyone else. On Mon, Sep 24, 2018 at 6:10 PM Jordan Harband <ljharb at gmail.com> wrote: > Are you familiar with the Temporal proposal? > https://github.com/tc39/proposal-temporal > > On Mon, Sep 24, 2018 at 8:32 PM, J Decker <d3ck0r at gmail.com> wrote: > >> I did look back to see other conversations about Dates.... >> >> Operating with arbitrary timezones >> https://mail.mozilla.org/pipermail/es-discuss/2016-August/046478.html >> >> Add timezone data to Date >> https://mail.mozilla.org/pipermail/es-discuss/2017-June/048259.html >> >> Even until this moment, Edge/IE cannot parse new Date( >> "2018-09-25T00:17:55.385-07:00"). which makes 50% of the world already >> require a date/time library. >> https://github.com/Microsoft/ChakraCore/issues/5502 >> (actually Aug 16 that was closed) >> >> Date.toISOString() only emits 'Z', even though the type itself has the >> offset >> >> as a Date.prototype.toISOLocalString() >> cb : function () { >> var tzo = -this.getTimezoneOffset(), >> dif = tzo >= 0 ? '+' : '-', >> pad = function(num) { >> var norm = Math.floor(Math.abs(num)); >> return (norm < 10 ? '0' : '') + norm; >> }; >> return this.getFullYear() + >> '-' + pad(this.getMonth() + 1) + >> '-' + pad(this.getDate()) + >> 'T' + pad(this.getHours()) + >> ':' + pad(this.getMinutes()) + >> ':' + pad(this.getSeconds()) + >> dif + pad(tzo / 60) + >> ':' + pad(tzo % 60); >> } >> ---------- >> But; that's only semi-accurate, because if I say -07:00 as the offset, I >> don't know if it's MST or PDT (which is knowable I suppose). >> >> There's not a LOT of usage of times in code; but it could be that the >> constant number 2018-09-25T00:26:00.741Z could just BE a Date, similar to >> 123n just being a BigInt. >> >> It would also be handy if there were a builtin ISO w/ Timezone emitter. >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180926/47cd8099/attachment.html>
I'm dealing with this these days too, and FWIW, I'm storing dates as
[date.toISOString(), date.getTimezoneOffset()]
so I can new Date(stored[0])
and if/when needed date.setMinutes(stored[1])
.
I know it's a work around, but it easily serves well all use cases I had.
I'm dealing with this these days too, and FWIW, I'm storing dates as `[date.toISOString(), date.getTimezoneOffset()]` so I can `new Date(stored[0])` and if/when needed `date.setMinutes(stored[1])`. I know it's a work around, but it easily serves well all use cases I had. Regards On Thu, Sep 27, 2018 at 1:54 AM J Decker <d3ck0r at gmail.com> wrote: > That's a little like using a sledge hammer to cut cake. > > Adding Dates as a type of data in JSOX, the additional rule to handle > dates in the parser is pretty simple. > https://raw.githubusercontent.com/d3x0r/JSOX/master/NumberRule.GIF > > I'm also not sure it's really needed to know if it was ' MST or PDT ' at > that time. With whatever the current offset was at that time, that's the > time it was for them (or the time they claim is for them), and the time it > was relative to everyone else. > > On Mon, Sep 24, 2018 at 6:10 PM Jordan Harband <ljharb at gmail.com> wrote: > >> Are you familiar with the Temporal proposal? >> https://github.com/tc39/proposal-temporal >> >> On Mon, Sep 24, 2018 at 8:32 PM, J Decker <d3ck0r at gmail.com> wrote: >> >>> I did look back to see other conversations about Dates.... >>> >>> Operating with arbitrary timezones >>> https://mail.mozilla.org/pipermail/es-discuss/2016-August/046478.html >>> >>> Add timezone data to Date >>> https://mail.mozilla.org/pipermail/es-discuss/2017-June/048259.html >>> >>> Even until this moment, Edge/IE cannot parse new Date( >>> "2018-09-25T00:17:55.385-07:00"). which makes 50% of the world already >>> require a date/time library. >>> https://github.com/Microsoft/ChakraCore/issues/5502 >>> (actually Aug 16 that was closed) >>> >>> Date.toISOString() only emits 'Z', even though the type itself has the >>> offset >>> >>> as a Date.prototype.toISOLocalString() >>> cb : function () { >>> var tzo = -this.getTimezoneOffset(), >>> dif = tzo >= 0 ? '+' : '-', >>> pad = function(num) { >>> var norm = Math.floor(Math.abs(num)); >>> return (norm < 10 ? '0' : '') + norm; >>> }; >>> return this.getFullYear() + >>> '-' + pad(this.getMonth() + 1) + >>> '-' + pad(this.getDate()) + >>> 'T' + pad(this.getHours()) + >>> ':' + pad(this.getMinutes()) + >>> ':' + pad(this.getSeconds()) + >>> dif + pad(tzo / 60) + >>> ':' + pad(tzo % 60); >>> } >>> ---------- >>> But; that's only semi-accurate, because if I say -07:00 as the offset, I >>> don't know if it's MST or PDT (which is knowable I suppose). >>> >>> There's not a LOT of usage of times in code; but it could be that the >>> constant number 2018-09-25T00:26:00.741Z could just BE a Date, similar to >>> 123n just being a BigInt. >>> >>> It would also be handy if there were a builtin ISO w/ Timezone emitter. >>> >>> >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180927/e9498bb1/attachment-0001.html>
I did look back to see other conversations about Dates....
Operating with arbitrary timezones esdiscuss/2016-August/046478
Add timezone data to Date esdiscuss/2017-June/048259
Even until this moment, Edge/IE cannot parse new Date( "2018-09-25T00:17:55.385-07:00"). which makes 50% of the world already require a date/time library. Microsoft/ChakraCore#5502 (actually Aug 16 that was closed)
Date.toISOString() only emits 'Z', even though the type itself has the offset
as a Date.prototype.toISOLocalString() cb : function () { var tzo = -this.getTimezoneOffset(), dif = tzo >= 0 ? '+' : '-',
pad = function(num) { var norm = Math.floor(Math.abs(num)); return (norm < 10 ? '0' : '') + norm; }; return this.getFullYear() + '-' + pad(this.getMonth() + 1) + '-' + pad(this.getDate()) + 'T' + pad(this.getHours()) + ':' + pad(this.getMinutes()) + ':' + pad(this.getSeconds()) + dif + pad(tzo / 60) + ':' + pad(tzo % 60); }
But; that's only semi-accurate, because if I say -07:00 as the offset, I don't know if it's MST or PDT (which is knowable I suppose).
There's not a LOT of usage of times in code; but it could be that the constant number 2018-09-25T00:26:00.741Z could just BE a Date, similar to 123n just being a BigInt.
It would also be handy if there were a builtin ISO w/ Timezone emitter.