Skip to content

Commit

Permalink
Make FixedTimeZone private
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Sep 14, 2022
1 parent 949fb99 commit 3ea74cc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
25 changes: 9 additions & 16 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::format::Locale;
#[cfg(any(feature = "alloc", feature = "std", test))]
use crate::format::{DelayedFormat, Item, StrftimeItems};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::offset::{FixedTimeZone, TimeZone, Utc};
use crate::offset::{TimeZone, Utc};
use crate::time_delta::TimeDelta;
use crate::{DateTime, Datelike, Error, Weekday};

Expand Down Expand Up @@ -209,13 +209,6 @@ impl<Tz: TimeZone> Date<Tz> {
tz.from_utc_date(&self.date)
}

/// Changes the associated time zone.
/// This does not change the actual `Date` (but will change the string representation).
#[inline]
pub fn with_fixed_timezone<Tz2: FixedTimeZone>(&self, tz: &Tz2) -> Date<Tz2> {
tz.from_utc_date_fixed(&self.date)
}

/// Adds given `Duration` to the current date.
///
/// Returns `Err(Error)` when it will result in overflow.
Expand Down Expand Up @@ -556,14 +549,14 @@ mod tests {
assert_eq!(date_add, date + TimeDelta::days(5));

let timezone = FixedOffset::east(60 * 60).unwrap();
let date = date.with_fixed_timezone(&timezone);
let date_add = date_add.with_fixed_timezone(&timezone);
let date = date.with_timezone(&timezone).unwrap();
let date_add = date_add.with_timezone(&timezone).unwrap();

assert_eq!(date_add, date + TimeDelta::days(5));

let timezone = FixedOffset::west(2 * 60 * 60).unwrap();
let date = date.with_fixed_timezone(&timezone);
let date_add = date_add.with_fixed_timezone(&timezone);
let date = date.with_timezone(&timezone).unwrap();
let date_add = date_add.with_timezone(&timezone).unwrap();

assert_eq!(date_add, date + TimeDelta::days(5));
}
Expand All @@ -590,14 +583,14 @@ mod tests {
assert_eq!(date_sub, date - TimeDelta::days(5));

let timezone = FixedOffset::east(60 * 60).unwrap();
let date = date.with_fixed_timezone(&timezone);
let date_sub = date_sub.with_fixed_timezone(&timezone);
let date = date.with_timezone(&timezone).unwrap();
let date_sub = date_sub.with_timezone(&timezone).unwrap();

assert_eq!(date_sub, date - TimeDelta::days(5));

let timezone = FixedOffset::west(2 * 60 * 60).unwrap();
let date = date.with_fixed_timezone(&timezone);
let date_sub = date_sub.with_fixed_timezone(&timezone);
let date = date.with_timezone(&timezone).unwrap();
let date_sub = date_sub.with_timezone(&timezone).unwrap();

assert_eq!(date_sub, date - TimeDelta::days(5));
}
Expand Down
2 changes: 1 addition & 1 deletion src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// Changes the associated time zone.
/// The returned `DateTime` references the same instant of time from the perspective of the provided time zone.
#[inline]
pub fn with_fixed_timezone<Tz2: FixedTimeZone>(&self, tz: &Tz2) -> DateTime<Tz2> {
pub(crate) fn with_fixed_timezone<Tz2: FixedTimeZone>(&self, tz: &Tz2) -> DateTime<Tz2> {
tz.from_utc_datetime_fixed(&self.datetime)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
//! // time zone accessor and manipulation
//! assert_eq!(dt.offset().fix().local_minus_utc(), 9 * 3600);
//! assert_eq!(dt.timezone(), FixedOffset::east(9 * 3600)?);
//! assert_eq!(dt.with_fixed_timezone(&Utc), Utc.ymd(2014, 11, 28)?.and_hms_nano(12, 45, 59, 324310806)?);
//! assert_eq!(dt.with_timezone(&Utc)?, Utc.ymd(2014, 11, 28)?.and_hms_nano(12, 45, 59, 324310806)?);
//!
//! // a sample of property manipulations (validates dynamically)
//! assert_eq!(dt.with_day(29)?.weekday(), Weekday::Sat); // 2014-11-29 is Saturday
Expand Down
2 changes: 1 addition & 1 deletion src/offset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ pub trait TimeZone: Sized + Clone {
/// A time zone that is fixed. It is distinguished from [TimeZone] by allowing
/// for infallible operations since there is no need to access system
/// information to figure out which timezone is being used.
pub trait FixedTimeZone: TimeZone {
pub(crate) trait FixedTimeZone: TimeZone {
/// Creates the offset for given UTC `NaiveDate`. This cannot fail.
fn offset_from_utc_date_fixed(&self, utc: &NaiveDate) -> Self::Offset;

Expand Down

0 comments on commit 3ea74cc

Please sign in to comment.