Skip to content

Commit

Permalink
Rename FixedOffset::{east_opt, west_opt}
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 29, 2024
1 parent 89e262f commit 7f05472
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 151 deletions.
8 changes: 4 additions & 4 deletions bench/benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn bench_datetime_from_str(c: &mut Criterion) {
}

fn bench_datetime_to_rfc2822(c: &mut Criterion) {
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
let pst = FixedOffset::east(8 * 60 * 60).unwrap();
let dt = pst
.from_local_datetime(
&NaiveDate::from_ymd_opt(2018, 1, 11)
Expand All @@ -50,7 +50,7 @@ fn bench_datetime_to_rfc2822(c: &mut Criterion) {
}

fn bench_datetime_to_rfc3339(c: &mut Criterion) {
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
let pst = FixedOffset::east(8 * 60 * 60).unwrap();
let dt = pst
.from_local_datetime(
&NaiveDate::from_ymd_opt(2018, 1, 11)
Expand All @@ -63,7 +63,7 @@ fn bench_datetime_to_rfc3339(c: &mut Criterion) {
}

fn bench_datetime_to_rfc3339_opts(c: &mut Criterion) {
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
let pst = FixedOffset::east(8 * 60 * 60).unwrap();
let dt = pst
.from_local_datetime(
&NaiveDate::from_ymd_opt(2018, 1, 11)
Expand Down Expand Up @@ -205,7 +205,7 @@ fn bench_naivedate_add_signed(c: &mut Criterion) {
}

fn bench_datetime_with(c: &mut Criterion) {
let dt = FixedOffset::east_opt(3600).unwrap().with_ymd_and_hms(2023, 9, 23, 7, 36, 0).unwrap();
let dt = FixedOffset::east(3600).unwrap().with_ymd_and_hms(2023, 9, 23, 7, 36, 0).unwrap();
c.bench_function("bench_datetime_with", |b| {
b.iter(|| black_box(black_box(dt).with_hour(12)).unwrap())
});
Expand Down
26 changes: 13 additions & 13 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// use chrono::prelude::*;
///
/// let date: DateTime<Utc> = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
/// let other: DateTime<FixedOffset> = FixedOffset::east_opt(23).unwrap().with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
/// let other: DateTime<FixedOffset> = FixedOffset::east(23).unwrap().with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap();
/// assert_eq!(date.date_naive(), other.date_naive());
/// ```
#[inline]
Expand Down Expand Up @@ -489,7 +489,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true),
/// "2018-01-26T18:30:09Z");
///
/// let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
/// let pst = FixedOffset::east(8 * 60 * 60).unwrap();
/// let dt = pst.from_local_datetime(&NaiveDate::from_ymd_opt(2018, 1, 26).unwrap().and_hms_micro_opt(10, 30, 9, 453_829).unwrap()).unwrap();
/// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true),
/// "2018-01-26T10:30:09+08:00");
Expand Down Expand Up @@ -595,7 +595,7 @@ impl Default for DateTime<Local> {

impl Default for DateTime<FixedOffset> {
fn default() -> Self {
FixedOffset::west_opt(0).unwrap().from_utc_datetime(&NaiveDateTime::default())
FixedOffset::west(0).unwrap().from_utc_datetime(&NaiveDateTime::default())
}
}

Expand All @@ -606,7 +606,7 @@ impl From<DateTime<Utc>> for DateTime<FixedOffset> {
/// Conversion is done via [`DateTime::with_timezone`]. Note that the converted value returned by
/// this will be created with a fixed timezone offset of 0.
fn from(src: DateTime<Utc>) -> Self {
src.with_timezone(&FixedOffset::east_opt(0).unwrap())
src.with_timezone(&FixedOffset::east(0).unwrap())
}
}

Expand Down Expand Up @@ -708,7 +708,7 @@ impl DateTime<FixedOffset> {
/// # use chrono::{DateTime, FixedOffset, TimeZone};
/// assert_eq!(
/// DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(),
/// FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
/// FixedOffset::east(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
/// );
/// ```
pub fn parse_from_rfc2822(s: &str) -> ParseResult<DateTime<FixedOffset>> {
Expand Down Expand Up @@ -759,7 +759,7 @@ impl DateTime<FixedOffset> {
///
/// let dt = DateTime::parse_from_str(
/// "1983 Apr 13 12:09:14.274 +0000", "%Y %b %d %H:%M:%S%.3f %z");
/// assert_eq!(dt, Ok(FixedOffset::east_opt(0).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(1983, 4, 13).unwrap().and_hms_milli_opt(12, 9, 14, 274).unwrap()).unwrap()));
/// assert_eq!(dt, Ok(FixedOffset::east(0).unwrap().from_local_datetime(&NaiveDate::from_ymd_opt(1983, 4, 13).unwrap().and_hms_milli_opt(12, 9, 14, 274).unwrap()).unwrap()));
/// ```
pub fn parse_from_str(s: &str, fmt: &str) -> ParseResult<DateTime<FixedOffset>> {
let mut parsed = Parsed::new();
Expand Down Expand Up @@ -788,7 +788,7 @@ impl DateTime<FixedOffset> {
/// "2015-02-18 23:16:09 +0200 trailing text", "%Y-%m-%d %H:%M:%S %z").unwrap();
/// assert_eq!(
/// datetime,
/// FixedOffset::east_opt(2*3600).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
/// FixedOffset::east(2*3600).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
/// );
/// assert_eq!(remainder, " trailing text");
/// ```
Expand Down Expand Up @@ -1138,8 +1138,8 @@ impl<Tz: TimeZone, Tz2: TimeZone> PartialOrd<DateTime<Tz2>> for DateTime<Tz> {
/// ```
/// use chrono::prelude::*;
///
/// let earlier = Utc.with_ymd_and_hms(2015, 5, 15, 2, 0, 0).unwrap().with_timezone(&FixedOffset::west_opt(1 * 3600).unwrap());
/// let later = Utc.with_ymd_and_hms(2015, 5, 15, 3, 0, 0).unwrap().with_timezone(&FixedOffset::west_opt(5 * 3600).unwrap());
/// let earlier = Utc.with_ymd_and_hms(2015, 5, 15, 2, 0, 0).unwrap().with_timezone(&FixedOffset::west(1 * 3600).unwrap());
/// let later = Utc.with_ymd_and_hms(2015, 5, 15, 3, 0, 0).unwrap().with_timezone(&FixedOffset::west(5 * 3600).unwrap());
///
/// assert_eq!(earlier.to_string(), "2015-05-15 01:00:00 -01:00");
/// assert_eq!(later.to_string(), "2015-05-14 22:00:00 -05:00");
Expand Down Expand Up @@ -1646,14 +1646,14 @@ where

assert_eq!(
to_string_fixed(
&FixedOffset::east_opt(3660).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
&FixedOffset::east(3660).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
)
.ok(),
Some(r#""2014-07-24T12:34:06+01:01""#.into())
);
assert_eq!(
to_string_fixed(
&FixedOffset::east_opt(3650).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
&FixedOffset::east(3650).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
)
.ok(),
// An offset with seconds is not allowed by RFC 3339, so we round it to the nearest minute.
Expand Down Expand Up @@ -1690,13 +1690,13 @@ fn test_decodable_json<FUtc, FFixed, FLocal, E>(
assert_eq!(
norm(&fixed_from_str(r#""2014-07-24T12:34:06Z""#).ok()),
norm(&Some(
FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
FixedOffset::east(0).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()
))
);
assert_eq!(
norm(&fixed_from_str(r#""2014-07-24T13:57:06+01:23""#).ok()),
norm(&Some(
FixedOffset::east_opt(60 * 60 + 23 * 60)
FixedOffset::east(60 * 60 + 23 * 60)
.unwrap()
.with_ymd_and_hms(2014, 7, 24, 13, 57, 6)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ mod tests {
}
impl Offset for TestTimeZone {
fn fix(&self) -> FixedOffset {
FixedOffset::east_opt(15 * 60 * 60).unwrap()
FixedOffset::east(15 * 60 * 60).unwrap()
}
}

Expand Down
Loading

0 comments on commit 7f05472

Please sign in to comment.