Skip to content

Commit

Permalink
Fix up internal calls to newly deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 28, 2022
1 parent f1cd7b0 commit 2e423e2
Show file tree
Hide file tree
Showing 32 changed files with 1,388 additions and 961 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -49,7 +49,7 @@ if you want.
Chrono inherently does not support an inaccurate or partial date and time representation.
Any operation that can be ambiguous will return `None` in such cases.
For example, "a month later" of 2014-01-30 is not well-defined
and consequently `Utc.ymd(2014, 1, 30).with_month(2)` returns `None`.
and consequently `Utc.ymd_opt(2014, 1, 30).unwrap().with_month(2)` returns `None`.

Non ISO week handling is not yet supported.
For now you can use the [chrono_ext](https://crates.io/crates/chrono_ext)
Expand Down
2 changes: 1 addition & 1 deletion ci/core-test/src/lib.rs
Expand Up @@ -3,5 +3,5 @@
use chrono::{TimeZone, Utc};

pub fn create_time() {
let _ = Utc.ymd(2019, 1, 1).and_hms(0, 0, 0);
let _ = Utc.ymd_opt(2019, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap();
}
20 changes: 10 additions & 10 deletions src/date.rs
Expand Up @@ -48,7 +48,7 @@ use crate::{Datelike, Weekday};
///
/// - Once constructed as a full `DateTime`, [`DateTime::date`] and other associated
/// methods should return those for the original `Date`. For example, if `dt =
/// tz.ymd(y,m,d).hms(h,n,s)` were valid, `dt.date() == tz.ymd(y,m,d)`.
/// tz.ymd_opt(y,m,d).unwrap().hms(h,n,s)` were valid, `dt.date() == tz.ymd_opt(y,m,d).unwrap()`.
///
/// - The date is timezone-agnostic up to one day (i.e. practically always),
/// so the local date and UTC date should be equal for most cases
Expand Down Expand Up @@ -337,7 +337,7 @@ where
/// ```rust
/// use chrono::prelude::*;
///
/// let date_time: Date<Utc> = Utc.ymd(2017, 04, 02);
/// let date_time: Date<Utc> = Utc.ymd_opt(2017, 04, 02).unwrap();
/// let formatted = format!("{}", date_time.format("%d/%m/%Y"));
/// assert_eq!(formatted, "02/04/2017");
/// ```
Expand Down Expand Up @@ -575,20 +575,20 @@ mod tests {

#[test]
fn test_date_add_assign() {
let naivedate = NaiveDate::from_ymd(2000, 1, 1);
let naivedate = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap();
let date = Date::<Utc>::from_utc(naivedate, Utc);
let mut date_add = date;

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

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

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

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

Expand All @@ -598,7 +598,7 @@ mod tests {
#[test]
#[cfg(feature = "clock")]
fn test_date_add_assign_local() {
let naivedate = NaiveDate::from_ymd(2000, 1, 1);
let naivedate = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap();

let date = Local.from_utc_date(&naivedate);
let mut date_add = date;
Expand All @@ -609,20 +609,20 @@ mod tests {

#[test]
fn test_date_sub_assign() {
let naivedate = NaiveDate::from_ymd(2000, 1, 1);
let naivedate = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap();
let date = Date::<Utc>::from_utc(naivedate, Utc);
let mut date_sub = date;

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

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

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

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

Expand All @@ -632,7 +632,7 @@ mod tests {
#[test]
#[cfg(feature = "clock")]
fn test_date_sub_assign_local() {
let naivedate = NaiveDate::from_ymd(2000, 1, 1);
let naivedate = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap();

let date = Local.from_utc_date(&naivedate);
let mut date_sub = date;
Expand Down

0 comments on commit 2e423e2

Please sign in to comment.