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.
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.
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.
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...
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.
"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.
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.
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.
28 comments
[ 5.0 ms ] story [ 67.8 ms ] threadThe best strategy is to suggest the [timezone|local shop|city name|whatever] and prompt for confirmation.
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.
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
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.
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.
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.
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.
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.
Abolishing time zones isn't necessarily a good idea.
(╯°□°)╯︵ ┻━┻