Skip to content

Commit

Permalink
Remove Date<Tz>
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 28, 2023
1 parent 296a5d9 commit 7c44bde
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 1,000 deletions.
666 changes: 0 additions & 666 deletions src/date.rs

This file was deleted.

25 changes: 1 addition & 24 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use crate::naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
#[cfg(feature = "clock")]
use crate::offset::Local;
use crate::offset::{FixedOffset, Offset, TimeZone, Utc};
#[allow(deprecated)]
use crate::Date;
use crate::{Datelike, Months, TimeDelta, Timelike, Weekday};

#[cfg(feature = "rkyv")]
Expand Down Expand Up @@ -148,28 +146,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
DateTime { datetime: datetime_utc, offset }
}

/// Retrieves the date component with an associated timezone.
///
/// Unless you are immediately planning on turning this into a `DateTime`
/// with the same timezone you should use the [`date_naive`](DateTime::date_naive) method.
///
/// [`NaiveDate`] is a more well-defined type, and has more traits implemented on it,
/// so should be preferred to [`Date`] any time you truly want to operate on dates.
///
/// # Panics
///
/// [`DateTime`] internally stores the date and time in UTC with a [`NaiveDateTime`]. This
/// method will panic if the offset from UTC would push the local date outside of the
/// representable range of a [`Date`].
#[inline]
#[deprecated(since = "0.4.23", note = "Use `date_naive()` instead")]
#[allow(deprecated)]
#[must_use]
pub fn date(&self) -> Date<Tz> {
Date::from_utc(self.naive_local().date(), self.offset.clone())
}

/// Retrieves the date component.
/// Retrieves the date without an associated timezone.
///
/// # Panics
///
Expand Down
8 changes: 1 addition & 7 deletions src/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ mod tests {

#[test]
fn test_serde_no_offset_debug() {
use crate::{LocalResult, NaiveDate, NaiveDateTime, Offset};
use crate::{LocalResult, NaiveDateTime, Offset};
use core::fmt::Debug;

#[derive(Clone)]
Expand All @@ -1213,18 +1213,12 @@ mod tests {
fn from_offset(_state: &TestTimeZone) -> TestTimeZone {
TestTimeZone
}
fn offset_from_local_date(&self, _local: &NaiveDate) -> LocalResult<TestTimeZone> {
LocalResult::Single(TestTimeZone)
}
fn offset_from_local_datetime(
&self,
_local: &NaiveDateTime,
) -> LocalResult<TestTimeZone> {
LocalResult::Single(TestTimeZone)
}
fn offset_from_utc_date(&self, _utc: &NaiveDate) -> TestTimeZone {
TestTimeZone
}
fn offset_from_utc_datetime(&self, _utc: &NaiveDateTime) -> TestTimeZone {
TestTimeZone
}
Expand Down
8 changes: 0 additions & 8 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ impl TimeZone for DstTester {
DstTester
}

fn offset_from_local_date(&self, _: &NaiveDate) -> crate::LocalResult<Self::Offset> {
unimplemented!()
}

fn offset_from_local_datetime(
&self,
local: &NaiveDateTime,
Expand Down Expand Up @@ -90,10 +86,6 @@ impl TimeZone for DstTester {
}
}

fn offset_from_utc_date(&self, _: &NaiveDate) -> Self::Offset {
unimplemented!()
}

fn offset_from_utc_datetime(&self, utc: &NaiveDateTime) -> Self::Offset {
let utc_to_winter_transition = NaiveDate::from_ymd_opt(
utc.year(),
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@ pub use time_delta::TimeDelta;

/// A convenience module appropriate for glob imports (`use chrono::prelude::*;`).
pub mod prelude {
#[doc(no_inline)]
#[allow(deprecated)]
pub use crate::Date;
#[cfg(feature = "clock")]
#[doc(no_inline)]
pub use crate::Local;
Expand All @@ -493,10 +490,6 @@ pub mod prelude {
pub use crate::{Offset, TimeZone};
}

mod date;
#[allow(deprecated)]
pub use date::{Date, MAX_DATE, MIN_DATE};

mod datetime;
#[allow(deprecated)]
pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME};
Expand Down
10 changes: 2 additions & 8 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use core::str::FromStr;
use rkyv::{Archive, Deserialize, Serialize};

use super::{LocalResult, Offset, TimeZone};
use crate::format::{scan, ParseError, OUT_OF_RANGE};
use crate::naive::{NaiveDate, NaiveDateTime};
use crate::format::{scan, OUT_OF_RANGE};
use crate::{NaiveDateTime, ParseError};

/// The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59.
///
Expand Down Expand Up @@ -128,16 +128,10 @@ impl TimeZone for FixedOffset {
*offset
}

fn offset_from_local_date(&self, _local: &NaiveDate) -> LocalResult<FixedOffset> {
LocalResult::Single(*self)
}
fn offset_from_local_datetime(&self, _local: &NaiveDateTime) -> LocalResult<FixedOffset> {
LocalResult::Single(*self)
}

fn offset_from_utc_date(&self, _utc: &NaiveDate) -> FixedOffset {
*self
}
fn offset_from_utc_datetime(&self, _utc: &NaiveDateTime) -> FixedOffset {
*self
}
Expand Down
25 changes: 1 addition & 24 deletions src/offset/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use rkyv::{Archive, Deserialize, Serialize};

use super::fixed::FixedOffset;
use super::{LocalResult, TimeZone};
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
#[allow(deprecated)]
use crate::Date;
use crate::{DateTime, Utc};
use crate::{DateTime, NaiveDateTime, Utc};

#[cfg(unix)]
#[path = "unix.rs"]
Expand Down Expand Up @@ -110,14 +107,6 @@ mod tz_info;
pub struct Local;

impl Local {
/// Returns a `Date` which corresponds to the current date.
#[deprecated(since = "0.4.23", note = "use `Local::now()` instead")]
#[allow(deprecated)]
#[must_use]
pub fn today() -> Date<Local> {
Local::now().date()
}

/// Returns a `DateTime<Local>` which corresponds to the current date, time and offset from
/// UTC.
///
Expand Down Expand Up @@ -157,22 +146,10 @@ impl TimeZone for Local {
Local
}

#[allow(deprecated)]
fn offset_from_local_date(&self, local: &NaiveDate) -> LocalResult<FixedOffset> {
// Get the offset at local midnight.
self.offset_from_local_datetime(&local.and_time(NaiveTime::MIN))
}

fn offset_from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult<FixedOffset> {
inner::offset_from_local_datetime(local)
}

#[allow(deprecated)]
fn offset_from_utc_date(&self, utc: &NaiveDate) -> FixedOffset {
// Get the offset at midnight.
self.offset_from_utc_datetime(&utc.and_time(NaiveTime::MIN))
}

fn offset_from_utc_datetime(&self, utc: &NaiveDateTime) -> FixedOffset {
inner::offset_from_utc_datetime(utc).unwrap()
}
Expand Down

0 comments on commit 7c44bde

Please sign in to comment.