-
Notifications
You must be signed in to change notification settings - Fork 2
Consider how to advance across a DST transition #34
Comments
I suppose this could also be written as any of the following: 1) DateTimeOffset result = dto.AddHours(2, tz);
2) DateTimeOffset result = tz.AddHours(dto, 2);
3) DateTimeOffset result = tz.Add(dto, TimeSpan.FromHours(2));
4) DateTimeOffset result = TimeZoneInfo.AddHours(dto, 2, tz);
5) DateTimeOffset result = TimeZoneInfo.Add(dto, TimeSpan.FromHours(2), tz); Please vote by number of which feels most natural to you. Thanks. |
Given the choices I kind of prefer the extension method off of The I think that these are good ideas but don't replace actually implementing additional proper date/time/tz types and behaviors. |
Moving ahead with the first option for now. I can change it later if we decide to go that route. See #35 for implementation (in progress). |
@HaloFour - for now, I'll focus on the |
After implementing the basic methods, I realized that it's not that much more work to allow for user-defined "resolvers", similar to Noda Time's This is advantageous because it lets us define a default behavior for dealing with gaps and overlaps without locking the user down to a single behaviior. See the PR for the implementation. |
@HaloFour to answer your questions:
There's a difference between the date-centric methods ( With the time-centric methods, it wouldn't matter if the offset matched or not. Essentially, it would have the same result as if the value was converted to UTC, the time was added there, and then it was converted to the specified time zone. However, with the date-centric methods, it wouldn't make much sense to take in a
I've updated the PR to include step 1, which I was missing before. |
Continuing the rest of the questions:
If the input time isn't valid, that's ok because it's adjusted as described earlier. If the output time isn't valid, or is ambiguous, that's when the resolver has value. The default resolver uses the same behavior as Java 8, and as Noda Time 2.0 (Noda Time 1.x had a different default behavior. See "Lenient resolver changes" at the bottom of this documentation). The behavior is as follows:
Again, these behaviors can be overridden by the user.
Well, if I implement the same kind of thing with Or - we could have it follow the same steps, but always return a |
Ok, I went ahead and added what I think is the correct implementation for |
Just adding a note to document this currently leaves |
@Clockwork-Muse - That's interesting when thinking about moving by months or years, since those are very-much specific to calendar. |
The methods on |
Merged the PR and closing this for now. We'll pick up the conversation after the migration to corefxlabs. We can either continue down this path, or backtrack if so decided. Thanks! |
There's currently no clean way to advance a
DateTime
or aDateTimeOffset
across a DST transition and end up in the right place. Either time will be off, or offset, or both.A
DateTimeZoned
type would be one way to handle this.Another way would be via method overloads that take a time zone, such as in the following example:
This would be clear for
DateTimeOffset
, it's not as clear forDateTime
, due to potential conflicts betweenTimeZoneInfo
andDateTimeKind
.Also consider what should be done if the input kind is Unspecified, but falls into an invalid or ambiguous value for the given time zone.
One possible solution is that these extension methods only exist on
DateTimeOffset
.The text was updated successfully, but these errors were encountered: