-
Notifications
You must be signed in to change notification settings - Fork 157
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
ZonedDateTime.toLocaleString() and last cookbook example #1153
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1153 +/- ##
==========================================
- Coverage 93.55% 90.63% -2.93%
==========================================
Files 19 17 -2
Lines 7961 8797 +836
Branches 1264 1245 -19
==========================================
+ Hits 7448 7973 +525
- Misses 506 813 +307
- Partials 7 11 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
The ZonedDateTime's time zone wins over the system's default time zone. If you explicitly give a time zone in the formatter options, and you try to format a ZonedDateTime with a time zone which is different from the explicitly given time zone, then toLocaleString() will throw an exception. formatRange() and formatRangeToParts() require ZonedDateTimes with the same time zone. See: #569
Now that ZonedDateTime.toLocaleString() works, we can fix this example. It becomes much simpler using ZonedDateTime. See: #569
In DateTimeFormat.format, we need to call toString() to get the calendar ID only once, instead of several times.
0240ac2
to
06ea4f4
Compare
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.
Looks good. I admittedly don't know much about the innards of toLocaleString so I focused my review on the cookbook sample and the high-level expectations like throwing if zones are mismatched.
|
||
// Show the date in midnight cells | ||
let formatOptions; | ||
if (dt.hour === 0) { | ||
if (columnTime.hour === 0) { |
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.
I think you probably want to compare columnTime to .startOfDay
here, not zero, if you want to handle cases where DST skips an hour starting at midnight.
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.
That's a good point, it does handle other skipped and repeated times gracefully, so it should here as well.
See: #569