-
Notifications
You must be signed in to change notification settings - Fork 101
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
WIP: Added ZonedDateTime #175
base: master
Are you sure you want to change the base?
Conversation
|
When you want to use static types to enforce minimum requirements. We might want to ensure we store non-ambiguous
That's just the name other APIs (e.g. java.time) use, but we can rename it to
|
In which case it would just be a OffsetDateTime right? And all the calendar usage traits would be gone. |
public constructor(instant: Instant, timeZone: TimeZone) : | ||
this(instant.toLocalDateTime(timeZone), timeZone) | ||
|
||
// TODO: Should RegionTimeZone.toString() print with surrounding `[]`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any standards for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostgreSQL, Elasticsearch, java.time, JS Temporal and others seem to have settled on this full format: 2021-03-28T03:16:20+02:00[Europe/Berlin]
Though, maybe RegionTimeZone itself should just be Europe/Berlin
and the surrounding []
would be added by RegionDateTime. Most libs will parse the region without the []
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I'd settle with the established format
public constructor(instant: Instant, timeZone: FixedOffsetTimeZone) : | ||
this(instant.toLocalDateTime(timeZone), timeZone) | ||
|
||
override fun toString(): String = "$localDateTime$timeZone" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be in RFC3339 as that's the common serialization and representation everywhere.
No, the UTC offset is used for disambiguation. The region is still needed. We need to handle these cases:
For calendar applications the region would always take precedence and the offset would be used to disambiguate only. Example: Your wedding event in Italy in 2024 at 14:00 must keep its local time at 14:00 even if Europe gets rid of DST handling in the meantime. So, the offset must be ignored unless there's an ambiguity and even then it should only used to handle DST offsets and never be applied literally. See also how others are doing it:
The only open question is whether we should support a DST flag in addition to UTC based offsets. If a country moves its time zone offset and this overlaps with a DST switch then a UTC offset alone can't correctly disambiguate the hour during a DST change. Only a DST flag could handle that edge case. Maybe that's too much of an edge case though and it may not even be clear what the user's original intent was. |
In that case I'd stick to the TC39 proposal, that looks quite good (there's also usually with at lot of peoples checking it). |
I port some JVM-related code and this exact class is needed. Hope that it gets merged... |
@kkocel most probably the |
@dkhalanskyjb actually I need to have a class that can be deserialized from the |
Initial sketch of
ZonedDateTime
: common base classRegionDateTime
: works for past and future dates and mimics how humans see datesOffsetDateTime
: how many official specifications represent past/present datesThis is still missing a
RegionTimeZone
to represent time zones based on a region id instead of just an offset. Not implemented yet:Also see discussion in #163
Feedback welcome.