Skip to content

Commit

Permalink
Remove workaround for Rust < 1.61
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 28, 2024
1 parent baa55d0 commit ca5e1e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
13 changes: 4 additions & 9 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// ```
#[inline]
#[must_use]
pub fn from_naive_utc_and_offset(datetime: NaiveDateTime, offset: Tz::Offset) -> DateTime<Tz> {
pub const fn from_naive_utc_and_offset(
datetime: NaiveDateTime,
offset: Tz::Offset,
) -> DateTime<Tz> {
DateTime { datetime, offset }
}

Expand Down Expand Up @@ -655,14 +658,6 @@ impl DateTime<Utc> {
NaiveDateTime::from_timestamp_millis(millis).as_ref().map(NaiveDateTime::and_utc)
}

// FIXME: remove when our MSRV is 1.61+
// This method is used by `NaiveDateTime::and_utc` because `DateTime::from_naive_utc_and_offset`
// can't be made const yet.
// Trait bounds in const function / implementation blocks were not supported until 1.61.
pub(crate) const fn from_naive_utc(datetime: NaiveDateTime) -> Self {
DateTime { datetime, offset: Utc }
}

/// The Unix Epoch, 1970-01-01 00:00:00 UTC.
pub const UNIX_EPOCH: Self = Self { datetime: NaiveDateTime::UNIX_EPOCH, offset: Utc };
}
Expand Down
3 changes: 1 addition & 2 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,7 @@ impl NaiveDateTime {
/// ```
#[must_use]
pub const fn and_utc(&self) -> DateTime<Utc> {
// FIXME: use `DateTime::from_naive_utc_and_offset` when our MSRV is 1.61+.
DateTime::from_naive_utc(*self)
DateTime::from_naive_utc_and_offset(*self, Utc)
}

/// The minimum possible `NaiveDateTime`.
Expand Down

0 comments on commit ca5e1e1

Please sign in to comment.