-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling of local time around DST #3
base: master
Are you sure you want to change the base?
Conversation
@mj1856 commented (via slack) WRT ambiguous/invalid, what we're currently doing in moment-timezone, is the same for what Noda Time and Java 8 do, and what Maggie and I have pushed for ECMAScript to define for the Date object. That is as follows:
|
By first you mean older? Also isn't daylight happening in the summer, which could be during winter months (in southern hemisphere), but it still moves forward then backwards, never in the other direction? Also when you say DST, can the time move and not be called DST (like dictator wants to align time with X... so no DST but time shift instead).
I got that, but then again -- you imply there are transitions not due to DST, I guess we need to use the same logic as for DST transitions.
For scheduling, isn't it safer to assume end times are the latter option for ambiguous (so the worker is not stripped one hour)? I wasn't aware that other libs were doing more or less the same, given how arbitrary browsers behave.
If now is 01:00, there is dst at 02:59->04:00 and you set the hour to 06, then if its UTC accurate it should add 5 hours, which would result in 07:00, but if its local accurate it would result in 06:00 (because it will try to be local accurate, adjust the offset and be happy). With UTC accurate there is only adding/subtracting (otherwise its not clear what to do). I have seen Safari do the UTC accurate hour (you Date.setHours(X), and the result is X+-1). So that is messed up! For adding my logic is -- if you add 1 hour -- that is pretty well defined unit, so the time that results should really be 1 hour away. Versus if you set, you want the final result to be with that hour, and there is no "correctness" to follow, other than preserve all other units if possible.
Well, I'm pretty sure there are DST transitions happening on 00:00 of the first of the month. I'm also talking more about a "hole" like 23:30 -> 00:30 (or even 23:59->01:00) If the time 00:00 is valid (i.e -- not invalid, but could be ambiguous) then picking the first one makes sense. Now that I think about it the default logic should be fine, but people keep complaining that moment doesn't handle start/end of around DST very well.
Ah, so here is a deviation from the rule above (pick the second offset, when ambiguous). I'm just saying we have to have logic to handle choice, then why not make it user-configurable (in a sane way).
Because I treat hours differently, as you saw earlier, and I didn't know the right terminology, I used mine :) |
@icambron commented (via slack)
|
On Matt's point 4, I think one way to clarify Iskren's point is that setters don't use units at all. For example, |
@icambron setting can always be viewed as adding the difference, and that could be UTC correct. That is how the lower units (minute, second, ms) are implemented. Or, you could argue, its not implemented like that, its like a brand new local time, but then -- how do you handle invalids and ambiguities? And you can handle them the same way as a brand new time. Rethinking most of my document, if there is already a preferred handling for invalid/ambiguities (pick daylight, approx), the doc can be seriously shortened. But if we want to support custom handling of those then at least presenting the possible options is necessary. |
@ichernev Like, if it's 1:00, then setting the hour to 4 could be done as adding 4-1 hours to the current timestamp? That's true, but seems unfathomably strange. In any case, we agree on how it should work. |
@icambron i agree its strange, but all other units work this way (while its mostly compatible with the pure setting perspective), even in Date. Setting the month basically adds 30-1 daya so from 31 jan setting feb you can end up in march. |
Yes, use the older of the two occurrences. DST is always in summer, it's just that the months that comprise "summer" in the Northern hemisphere are different than those in the summer hemisphere. (Don't think of it as winter.)
Yes, a transition can occur that is not related to DST, such as a change in the standard-time offset. These are usually singular transitions, rather than being paired like DST. An example would be when Venezuela moved from +4:30 to +4:00 in 2016 by advancing their clocks forward 30 minutes. All transitions should be handled the same, regardless of their cause. They are either forward-moving (creating a gap of invalid local time) or backward-moving (creating an overlap of ambiguous local time), and the amount of the gap/overlap can be anything.
By "scheduling" I mean more like scheduling an automated task that has some recurrence pattern, such as "do this thing daily at 2:00 am". It makes no sense to skip over the first occurrence and wait for the second one. WRT scheduling of people taking shifts, @maggiepint and I discussed this, since we both worked in this space previously. Typically, a worker is either scheduled to work through the DST period in entirety, thus earning an extra hour pay and creating no ambiguity, or is explicitly scheduled to end before the DST period begins. In the rare case that they would be scheduled for a portion of the extra DST period (ex: ending their shift at 1:30 am), if they were required to work until the second occurrence, then the scheduling system should deliberately call that out. It's not something we would want to choose as a default.
I never think of setters as adders. It's "assign a value to this field", then "adjust to a valid instant if invalid or ambiguous". If a moment is in UTC mode, then there's nothing to do but set. In local mode, we're currently relying on the Date object's behavior for moment, but we are going through the ambiguous/invalid logic in moment-timezone.
A transition at 00:00 doesn't create an ambiguous date. It goes from 23:59:59.999 back to 23:00:00.000. The hole you describe is technically possible, but impractical and non-existent in real life.
Yep. End-of-time is special cased. |
Honestly, I don't understand why we are re-hashing how to handle these things. Really we just need to clean up the interface between moment and moment-timezone. |
@mj1856 well, cleaning it up involves the part where we write in moment how to "interpret" the moment-timezone (or other plugin) data, which will be in the form of (at least) UTC-timestamp -> utc-offset. So I got it, that we should use the default behavior when creating/setting and the described behavior during add/subtract and startof/endof. But there are still questions about what other functions to provide (like previous/next offset change), so moment doesn't have to do binary search to figure out how big the time-shift is (as you said -- it could be any amount, not just 1h). |
readable