Skip to content
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

Remove workaround for Rust < 1.61 #1393

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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