Closed pitdicker closed 6 months ago
Attention: Patch coverage is 99.64158%
with 2 lines
in your changes are missing coverage. Please review.
Project coverage is 93.95%. Comparing base (
3317fd1
) to head (fa27e5c
).:exclamation: Current head fa27e5c differs from pull request most recent head f80253c. Consider uploading reports for the commit f80253c to get more accurate results
Files | Patch % | Lines |
---|---|---|
src/datetime/tests.rs | 98.34% | 2 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
So we may have this and_()
pattern but I feel like with_()
is much more common in the Rust ecosystem. Maybe we should be moving in the other direction instead? (I think that was the idea behind with_ymd_and_hms()
, at least.)
Can we do some part of this on main?
Fine by me. Then we should probably rename the current with_
methods such as with_year
to something like replace_year
? That matches time-rs.
How are the semantics for current with_()
methods different from those for current and_()
methods, in your opinion?
Currently the with_()
methods return the same type and replace some part of the date, time or offset.
The and_()
methods add more information to turn it into another type.
Other methods that start with and
are NaiveDate::{and_time, and_hms*}
, NaiveDateTime::{and_local_timezone, and_utc}
.
And one more that starts with with
is DateTime::with_timezone
.
I'll collect some info in an issue.
Added commits to rename all methods from #1527 except TimeZone::{from_local_datetime, from_utc_datetime}
.
I am not 100% conviced with the new names for NaiveDateTime::{and_local_timezone, and_utc}
. Naming them in_
does match natural language. And assume_
seems like saying the user may not be sure for some reason.
Example code:
let pst = FixedOffset::east(8 * 60 * 60)?;
// in_timezone
let dt = NaiveDate::from_ymd(2018, 1, 11)?.at_hms(10, 5, 13)?.in_timezone(pst);
// assume_timezone
let dt = NaiveDate::from_ymd(2018, 1, 11)?.at_hms(10, 5, 13)?.assume_timezone(pst);
// in_utc
let timestamp = NaiveDate::from_ymd(1970, 1, 1)?.at_hms(0, 0, 0).in_utc().timestamp();
// assume_utc
let timestamp = NaiveDate::from_ymd(1970, 1, 1)?.at_hms(0, 0, 0).assume_utc().timestamp();
We have the pattern to use the name
and_
for methods that add information to convert to a more complete type.NaiveDate
hadand_time
andand_hms*
,NaiveDateTime
hasand_local_timezone
.This makes the methods on
TimeZone
consistent.TimeZone::timestamp*
is renamed toTimeZone::and_timestamp*
andTimeZone::with_ymd_and_hms
toTimeZone::and_ymd_and_hms*
.