Dates with Timezones and ISO8601 Date Constants.

# J Decker (6 years ago)

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.

# Jordan Harband (6 years ago)

Are you familiar with the Temporal proposal? tc39/proposal

# J Decker (6 years ago)

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.

# Andrea Giammarchi (6 years ago)

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.