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 3b061fd commit f166892
Show file tree
Hide file tree
Showing 32 changed files with 1,414 additions and 941 deletions.
21 changes: 10 additions & 11 deletions README.md
@@ -1,5 +1,4 @@
[Chrono][docsrs]: Date and Time for Rust
========================================
# [Chrono][docsrs]: Date and Time for Rust

[![Chrono GitHub Actions][gh-image]][gh-checks]
[![Chrono on crates.io][cratesio-image]][cratesio]
Expand All @@ -19,17 +18,17 @@ It aims to be a feature-complete superset of
the [time](https://github.com/rust-lang-deprecated/time) library.
In particular,

* Chrono strictly adheres to ISO 8601.
* Chrono is timezone-aware by default, with separate timezone-naive types.
* Chrono is space-optimal and (while not being the primary goal) reasonably efficient.
- Chrono strictly adheres to ISO 8601.
- Chrono is timezone-aware by default, with separate timezone-naive types.
- Chrono is space-optimal and (while not being the primary goal) reasonably efficient.

There were several previous attempts to bring a good date and time library to Rust,
which Chrono builds upon and should acknowledge:

* [Initial research on
the wiki](https://github.com/rust-lang/rust-wiki-backup/blob/master/Lib-datetime.md)
* Dietrich Epp's [datetime-rs](https://github.com/depp/datetime-rs)
* Luis de Bethencourt's [rust-datetime](https://github.com/luisbg/rust-datetime)
- [Initial research on
the wiki](https://github.com/rust-lang/rust-wiki-backup/blob/master/Lib-datetime.md)
- Dietrich Epp's [datetime-rs](https://github.com/depp/datetime-rs)
- Luis de Bethencourt's [rust-datetime](https://github.com/luisbg/rust-datetime)

## Limitations

Expand All @@ -42,14 +41,14 @@ Time types are limited in the nanosecond accuracy.
[Leap seconds are supported in the representation but
Chrono doesn't try to make use of them](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveTime.html#leap-second-handling).
(The main reason is that leap seconds are not really predictable.)
Almost *every* operation over the possible leap seconds will ignore them.
Almost _every_ operation over the possible leap seconds will ignore them.
Consider using `NaiveDateTime` with the implicit TAI (International Atomic Time) scale
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 f166892

Please sign in to comment.