Add DateTime::to_timezone and FromOffset trait#1569
Add DateTime::to_timezone and FromOffset trait#1569pitdicker wants to merge 1 commit intochronotope:mainfrom
DateTime::to_timezone and FromOffset trait#1569Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1569 +/- ##
==========================================
+ Coverage 91.80% 91.83% +0.02%
==========================================
Files 37 37
Lines 18151 18198 +47
==========================================
+ Hits 16664 16712 +48
+ Misses 1487 1486 -1 ☔ View full report in Codecov by Sentry. |
This all sounds kind of speculative and not as a current/near-future thing? If so, I'd rather hold off on merging this now. Alternatively stated: what do you envision to be the concrete near-term benefit for our users? |
|
I hope to prove it useful soon. Fine to hold off for now. |
We can't have a generic
FromorIntoimplementation that converts from oneOffsettype into another because the standard library has a blanket implementation ofFrom<T> for T. For the same reason we can't have a genericFromorIntoimplementation that converts from oneDateTime<Tz>into another.So we can and do have implementations to convert between
DateTime<Utc>,DateTime<FixedOffset>andDateTime<Local>. But anyTimeZonetype outside chrono doesn't have this convenience, such as the one in chrono-tz.I propose to add a
FromOffsettrait thatOffsettypes can implement to convert from any genericOffset. And to add aDateTime::to_timezonemethod to conveniently convert aDateTime<Tz>into another type.If we implement
FromOffsetin chrono-tz it we can do nice things such as converting fromFixedOffsetto aTztime zone for a fixed offset, or eventually fromLocalOffset(#1563) to aTzwith the same time zone if possible.