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

0.4.x: deprecate methods that have an _opt() alternative #827

Merged
merged 3 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix up internal calls to newly deprecated methods
  • Loading branch information
djc committed Oct 3, 2022
commit c5ebbcd5a3710661b855699f7e5dd43877dad372
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading