News for hackers. Stuff that matters.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by tdy721 on Wednesday February 10, 2016 @05:51PM (#11076821)
Everything with timezones in a disaster, and the solution always seems to be a unix timestamp that is converted to human readable form at the last possible moment...
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by colanderman on Thursday February 11, 2016 @12:07AM (#11078346)
Unix timestamps cause a barrel of fun when leap seconds roll around. See e.g. https://access.redhat.com/articles/15145#known

Trivia: "Unix time" is not seconds since midnight January 1, 1970 UTC. It in fact represents the number of full days since January 1, 1972 UTC, plus 730, times 86400, plus the number of seconds since midnight. Due to this definition, it is not monotonic, as it may occasionally have discontinuities of 1 second (in either direction!) due to leap seconds.

Best is to just count seconds since some epoch (e.g. Unix time based on TAI rather than UTC), but not many systems actually do this.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by Johnny_Brahms on Thursday February 11, 2016 @02:07AM (#11078657)
We were bitten by this once, and we ended up relying on TAI and then making leap second deviations _very_ clear to users.

I never really got what the problem was, but apparently someone had been careless about comparing times on some transaction which ended up giving a client a bad day.

This was some time ago, and if this stuff actually matters to you you probably know how to deal with it.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by lightblade on Wednesday February 10, 2016 @06:03PM (#11076928)
Nope, use ISO 8601 format just like blog post suggested. It's more readable and not vulnerable to the Year 2038 problem [1].

It's also important to note that ISO 8601 format is the default format that Date object serialize to. Try it new Date().toJSON()

[1]: https://en.wikipedia.org/wiki/Year_2038_problem

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by cbd1984 on Wednesday February 10, 2016 @09:02PM (#11077764)
Unix timestamps aren't vulnerable to the Year 2038 Problem unless you deliberately make it so they are.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by tdeck on Wednesday February 10, 2016 @11:20PM (#11078210)
The problem with ISO 8601 is that it isn't as simple as it looks. A lot of implementations that claim to support ISO 8601 do not parse all the different formats allowed by the standard. There are all kinds of weird edge cases like specifying a date with a year and week number that are valid.

RFC3339 defines a subset that is only the sane tinestamp format most people probably think of when they think ISO8601. It's a good alternative, although a lot of the time UNIX timestamps are honestly the most convenient option for everyone.

Source: spent a bunch of time designing a public API and thinking about this.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by kbart on Thursday February 11, 2016 @04:11AM (#11079098)
"It's more readable and not vulnerable to the Year 2038 problem"

What makes you use signed 32-bit Integer for Unix timestamp in this age and day? I work with embedded systems and use Unix timestamp extensively, but never have I found any serious reason to use it as int32_t.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by al2o3cr on Thursday February 11, 2016 @08:21AM (#11079918)
My favorite is still:

    new Date('2016-02-11') !== new Date(2016,1,11)
One is midnight in the local TZ, other is midnight in UTC.

(╯°□°)╯︵ ┻━┻

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by danrisso3 on Thursday February 11, 2016 @11:48AM (#11081258)
Not to say that one is in February, the other in January.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by rgrove on Thursday February 11, 2016 @01:03PM (#11081751)
They're both in February. Months represented by integers start at 0.

    > new Date(2016,1,11)
    Thu Feb 11 2016 00:00:00 GMT-0800 (PST)
    > new Date('2016-02-11')
    Wed Feb 10 2016 16:00:00 GMT-0800 (PST)
I make the same mistake constantly even though I learned this years ago.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by khgvljhkb on Thursday February 11, 2016 @05:54AM (#11079420)
The french did a great job reforming measurements for weight, length, volume, etc with the metric system.

Let's do the same for time - no more time zones, make the base unit a day and then it can be divided or multiplied in the 10s, 100s, 1000s, etc.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by cbd1984 on Friday February 12, 2016 @01:32AM (#11085647)
http://qntm.org/abolish

Abolishing time zones isn't necessarily a good idea.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by meapix on Thursday February 11, 2016 @08:26AM (#11079933)
Good luck with that!
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by khgvljhkb on Thursday February 11, 2016 @09:27AM (#11080273)
If the whole world could unite with a better system of measure of space (meter) then the same can happen for measures of time.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by draw_down on Wednesday February 10, 2016 @04:22PM (#11076092)
As much as I like JS, everything involving it and dates/timezones is a giant disaster.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by projct on Wednesday February 10, 2016 @04:23PM (#11076100)
time is a giant disaster in every language and environment I've ever encountered :P
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by mikehollinger on Wednesday February 10, 2016 @05:58PM (#11076876)
https://www.youtube.com/watch?v=-5wpm-gesOY is a pretty entertaining video that talks about the various hoops developers must jump through.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by com2kid on Thursday February 11, 2016 @02:10AM (#11078665)
I work in embedded.

We have to do this on our own.

It is every bit as painful as it is made out to be.

A common problem that I don't see discussed much is the difference between recording when a time took place (just record and store it in UTC!) and then translating that into what the user expects to see. This is especially hard if you have information that should be grouped into "days", and a use case where the user changes time zones but may expect the same "relative to originally recorded time" to be shown when viewing past events.

A nightmare case.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by douche on Wednesday February 10, 2016 @06:05PM (#11076942)
If you haven't seen this, you should. Quite possibly my favorite youtube video, and this channel has a number of other great clips.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by draw_down on Wednesday February 10, 2016 @04:25PM (#11076129)
Yes. But front-end JS takes it to the next level by, for example, not providing any sane way to get the current locale.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by xlm1717 on Wednesday February 10, 2016 @04:59PM (#11076413)
Just don't do it on the front-end. Never do it on the front-end.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by draw_down on Wednesday February 10, 2016 @05:47PM (#11076785)
You have to. User specifies thing should happen at 2PM, their time, then POSTs that data to your API or whatever. Well, what time are they actually talking about? You need to know.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by toomuchtodo on Wednesday February 10, 2016 @08:03PM (#11077531)
You ask the user what time zone they're in? Better to have accurate data then guess.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by redrummr on Thursday February 11, 2016 @02:19AM (#11078696)
Especially considering this is consistent with not identifying the device beyond headers sent etc. and you can't just use an IP address to map the timezone as it may be shared at the tower/exchange kilometres away (DSL) or hundreds of kilometres away (wireless/cell) and cross timezones.

The best strategy is to suggest the [timezone|local shop|city name|whatever] and prompt for confirmation.

Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by douche on Wednesday February 10, 2016 @05:42PM (#11076750)
Moment.js is a must-have.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by nstr007 on Wednesday February 10, 2016 @06:11PM (#11076976)
If only we didn't need to add so much to our payload just to handle dates.
Re:JavaScript's “new Date()” causing 90% of Alibaba's intern... by ErikAugust on Wednesday February 10, 2016 @10:06PM (#11077982)
getTimezoneOffset()