-
Notifications
You must be signed in to change notification settings - Fork 508
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
Fallible variants for TimeZone::from_utc_*
#1499
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1499 +/- ##
==========================================
- Coverage 91.80% 91.78% -0.03%
==========================================
Files 40 40
Lines 18338 18369 +31
==========================================
+ Hits 16836 16860 +24
- Misses 1502 1509 +7 ☔ View full report in Codecov by Sentry. |
c1ccc1a
to
dd9933c
Compare
/// from for example an OS API, in which case this method returns `None`. | ||
#[inline] | ||
#[must_use] | ||
pub fn with_timezone_opt<Tz2: TimeZone>(&self, tz: &Tz2) -> Option<DateTime<Tz2>> { |
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.
Something I've been thinking about: for newly fallible API, shouldn't we directly start to yield some kind of Result
instead of sticking with Option
everywhere?
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 sometimes think the same. On the other hand it would make the API seem even less consistent if we end up with a handful of methods that return Result
and the rest returns Option
.
dd9933c
to
84806bd
Compare
I feel like these changes add friction to the 0.4 versions for little benefit. I'd like to only do this on the 0.5 branch and directly return an error type. |
As discussed in #1448 (comment):
The first commit adds
TimeZone::offset_from_utc_datetime_opt
,Timezone::from_utc_datetime_opt
andDateTime::with_timezone_opt
.The second makes our platform implementations for
Local
return anOption
(instead of going throughLocalResult
).The third commit goes through all uses of the existing three methods and changes them to propagate the error, or switch to the infallible
DateTime::to_utc
andDateTime::fixed_offset
. In cases where we still need to panic I usedexpect
instead of hiding the panic case behind another layer.For the rest I adjusted the tests to make it easy to switch to fallible methods on the 0.5 branch.