From 03bcfe9f28450c723e32793ecd778f658eda7f02 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Fri, 25 Oct 2024 06:08:07 -0400 Subject: [PATCH] Skip formatting some macros, update UI tests --- rustfmt.toml | 3 +- tests/compile-fail/invalid_date.rs | 14 +- tests/compile-fail/invalid_date.stderr | 62 +- tests/compile-fail/invalid_datetime.rs | 8 +- tests/compile-fail/invalid_datetime.stderr | 24 +- tests/compile-fail/invalid_serializer.rs | 2 +- tests/compile-fail/invalid_serializer.stderr | 42 +- tests/compile-fail/invalid_time.stderr | 26 +- tests/date.rs | 1092 ++++++++--------- tests/derives.rs | 4 +- tests/formatting.rs | 110 +- tests/macros.rs | 2 +- tests/offset_date_time.rs | 172 ++- tests/parsing.rs | 48 +- tests/primitive_date_time.rs | 214 ++-- tests/serde/json.rs | 2 +- tests/serde/macros.rs | 2 +- time/src/date.rs | 283 ++--- .../format_description/parse/format_item.rs | 2 +- time/src/macros.rs | 6 +- time/src/offset_date_time.rs | 76 +- time/src/primitive_date_time.rs | 74 +- time/src/serde/mod.rs | 2 +- 23 files changed, 1046 insertions(+), 1224 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 51d66b754f..ae509e724b 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -10,7 +10,8 @@ format_code_in_doc_comments = true format_macro_bodies = true format_macro_matchers = true format_strings = true -imports_granularity = "Module" group_imports = "StdExternalCrate" +imports_granularity = "Module" normalize_doc_attributes = true +skip_macro_invocations = ["date", "time", "offset"] wrap_comments = true diff --git a/tests/compile-fail/invalid_date.rs b/tests/compile-fail/invalid_date.rs index 3605ae80bf..f4c4000c4f 100644 --- a/tests/compile-fail/invalid_date.rs +++ b/tests/compile-fail/invalid_date.rs @@ -2,16 +2,16 @@ use time::macros::date; fn main() { let _ = date!(+1_000_000-01-01); - let _ = date!(10_000 - 01 - 01); + let _ = date!(10_000-01-01); let _ = date!(2021-W 60-1); let _ = date!(2021-W 01-0); let _ = date!(2021-W 01-8); - let _ = date!(2021 - 00 - 01); - let _ = date!(2021 - 13 - 01); - let _ = date!(2021 - 01 - 00); - let _ = date!(2021 - 01 - 32); - let _ = date!(2021 - 000); - let _ = date!(2021 - 366); + let _ = date!(2021-00-01); + let _ = date!(2021-13-01); + let _ = date!(2021-01-00); + let _ = date!(2021-01-32); + let _ = date!(2021-000); + let _ = date!(2021-366); let _ = date!(0a); let _ = date!(2021:); let _ = date!(2021-W 0a); diff --git a/tests/compile-fail/invalid_date.stderr b/tests/compile-fail/invalid_date.stderr index 3bf9d34ebe..afba3fdd0e 100644 --- a/tests/compile-fail/invalid_date.stderr +++ b/tests/compile-fail/invalid_date.stderr @@ -1,107 +1,107 @@ error: invalid component: year was 1000000 - --> $DIR/invalid_date.rs:4:19 + --> ../tests/compile-fail/invalid_date.rs:4:19 | 4 | let _ = date!(+1_000_000-01-01); | ^^^^^^^^^^ error: years with more than four digits must have an explicit sign - --> $DIR/invalid_date.rs:5:19 + --> ../tests/compile-fail/invalid_date.rs:5:19 | -5 | let _ = date!(10_000 - 01 - 01); +5 | let _ = date!(10_000-01-01); | ^^^^^^ error: invalid component: week was 60 - --> $DIR/invalid_date.rs:6:24 + --> ../tests/compile-fail/invalid_date.rs:6:24 | 6 | let _ = date!(2021-W 60-1); | ^^^^ error: invalid component: day was 0 - --> $DIR/invalid_date.rs:7:29 + --> ../tests/compile-fail/invalid_date.rs:7:29 | 7 | let _ = date!(2021-W 01-0); | ^ error: invalid component: day was 8 - --> $DIR/invalid_date.rs:8:29 + --> ../tests/compile-fail/invalid_date.rs:8:29 | 8 | let _ = date!(2021-W 01-8); | ^ error: invalid component: month was 0 - --> $DIR/invalid_date.rs:9:26 + --> ../tests/compile-fail/invalid_date.rs:9:24 | -9 | let _ = date!(2021 - 00 - 01); - | ^^ +9 | let _ = date!(2021-00-01); + | ^^ error: invalid component: month was 13 - --> $DIR/invalid_date.rs:10:26 + --> ../tests/compile-fail/invalid_date.rs:10:24 | -10 | let _ = date!(2021 - 13 - 01); - | ^^ +10 | let _ = date!(2021-13-01); + | ^^ error: invalid component: day was 0 - --> $DIR/invalid_date.rs:11:31 + --> ../tests/compile-fail/invalid_date.rs:11:27 | -11 | let _ = date!(2021 - 01 - 00); - | ^^ +11 | let _ = date!(2021-01-00); + | ^^ error: invalid component: day was 32 - --> $DIR/invalid_date.rs:12:31 + --> ../tests/compile-fail/invalid_date.rs:12:27 | -12 | let _ = date!(2021 - 01 - 32); - | ^^ +12 | let _ = date!(2021-01-32); + | ^^ error: invalid component: ordinal was 0 - --> $DIR/invalid_date.rs:13:26 + --> ../tests/compile-fail/invalid_date.rs:13:24 | -13 | let _ = date!(2021 - 000); - | ^^^ +13 | let _ = date!(2021-000); + | ^^^ error: invalid component: ordinal was 366 - --> $DIR/invalid_date.rs:14:26 + --> ../tests/compile-fail/invalid_date.rs:14:24 | -14 | let _ = date!(2021 - 366); - | ^^^ +14 | let _ = date!(2021-366); + | ^^^ error: invalid component: year was 0a - --> $DIR/invalid_date.rs:15:19 + --> ../tests/compile-fail/invalid_date.rs:15:19 | 15 | let _ = date!(0a); | ^^ error: unexpected token: : - --> $DIR/invalid_date.rs:16:23 + --> ../tests/compile-fail/invalid_date.rs:16:23 | 16 | let _ = date!(2021:); | ^ error: invalid component: week was 0a - --> $DIR/invalid_date.rs:17:26 + --> ../tests/compile-fail/invalid_date.rs:17:26 | 17 | let _ = date!(2021-W 0a); | ^^ error: unexpected token: : - --> $DIR/invalid_date.rs:18:28 + --> ../tests/compile-fail/invalid_date.rs:18:28 | 18 | let _ = date!(2021-W 01:); | ^ error: invalid component: day was 0a - --> $DIR/invalid_date.rs:19:29 + --> ../tests/compile-fail/invalid_date.rs:19:29 | 19 | let _ = date!(2021-W 01-0a); | ^^ error: invalid component: month or ordinal was 0a - --> $DIR/invalid_date.rs:20:24 + --> ../tests/compile-fail/invalid_date.rs:20:24 | 20 | let _ = date!(2021-0a); | ^^ error: invalid component: day was 0a - --> $DIR/invalid_date.rs:21:27 + --> ../tests/compile-fail/invalid_date.rs:21:27 | 21 | let _ = date!(2021-01-0a); | ^^ diff --git a/tests/compile-fail/invalid_datetime.rs b/tests/compile-fail/invalid_datetime.rs index 5fe4138eea..5d0a7ac56e 100644 --- a/tests/compile-fail/invalid_datetime.rs +++ b/tests/compile-fail/invalid_datetime.rs @@ -1,8 +1,8 @@ use time::macros::datetime; fn main() { - let _ = datetime!(2021 - 000 0:00); - let _ = datetime!(2021 - 001 24:00); - let _ = datetime!(2021 - 001 0:00 0); - let _ = datetime!(2021 - 001 0:00 UTC x); + let _ = datetime!(2021-000 0:00); + let _ = datetime!(2021-001 24:00); + let _ = datetime!(2021-001 0:00 0); + let _ = datetime!(2021-001 0:00 UTC x); } diff --git a/tests/compile-fail/invalid_datetime.stderr b/tests/compile-fail/invalid_datetime.stderr index d65e42760d..6068e1f5a1 100644 --- a/tests/compile-fail/invalid_datetime.stderr +++ b/tests/compile-fail/invalid_datetime.stderr @@ -1,23 +1,23 @@ error: invalid component: ordinal was 0 - --> $DIR/invalid_datetime.rs:4:30 + --> ../tests/compile-fail/invalid_datetime.rs:4:28 | -4 | let _ = datetime!(2021 - 000 0:00); - | ^^^ +4 | let _ = datetime!(2021-000 0:00); + | ^^^ error: invalid component: hour was 24 - --> $DIR/invalid_datetime.rs:5:34 + --> ../tests/compile-fail/invalid_datetime.rs:5:32 | -5 | let _ = datetime!(2021 - 001 24:00); - | ^^ +5 | let _ = datetime!(2021-001 24:00); + | ^^ error: unexpected token: 0 - --> $DIR/invalid_datetime.rs:6:39 + --> ../tests/compile-fail/invalid_datetime.rs:6:37 | -6 | let _ = datetime!(2021 - 001 0:00 0); - | ^ +6 | let _ = datetime!(2021-001 0:00 0); + | ^ error: unexpected token: x - --> $DIR/invalid_datetime.rs:7:43 + --> ../tests/compile-fail/invalid_datetime.rs:7:41 | -7 | let _ = datetime!(2021 - 001 0:00 UTC x); - | ^ +7 | let _ = datetime!(2021-001 0:00 UTC x); + | ^ diff --git a/tests/compile-fail/invalid_serializer.rs b/tests/compile-fail/invalid_serializer.rs index 284d0b783d..15671f14e9 100644 --- a/tests/compile-fail/invalid_serializer.rs +++ b/tests/compile-fail/invalid_serializer.rs @@ -11,6 +11,6 @@ serde::format_description!(my_format, OffsetDateTime,); // missing string format serde::format_description!(my_format, OffsetDateTime "[year] [month]"); // missing comma serde::format_description!(my_format, OffsetDateTime : "[year] [month]"); // not a comma serde::format_description!(my_format, OffsetDateTime, "[bad]"); // bad component name -serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type +serde::format_description!(my_format, OffsetDateTime, not_string); // not in scope fn main() {} diff --git a/tests/compile-fail/invalid_serializer.stderr b/tests/compile-fail/invalid_serializer.stderr index 3579ac33c7..0a14e7486c 100644 --- a/tests/compile-fail/invalid_serializer.stderr +++ b/tests/compile-fail/invalid_serializer.stderr @@ -72,42 +72,8 @@ error: invalid component 13 | serde::format_description!(my_format, OffsetDateTime, "[bad]"); // bad component name | ^^^^^^^ -error[E0432]: unresolved import `not_string` - --> ../tests/compile-fail/invalid_serializer.rs:14:1 +error[E0425]: cannot find value `not_string` in this scope + --> ../tests/compile-fail/invalid_serializer.rs:14:55 | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no external crate `not_string` - | - = note: this error originates in the macro `serde::format_description` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0391]: cycle detected when computing type of opaque `my_format::description::{opaque#0}` - --> ../tests/compile-fail/invalid_serializer.rs:14:1 - | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires borrow-checking `my_format::description`... - --> ../tests/compile-fail/invalid_serializer.rs:14:1 - | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires promoting constants in MIR for `my_format::description`... - --> ../tests/compile-fail/invalid_serializer.rs:14:1 - | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires const checking `my_format::description`... - --> ../tests/compile-fail/invalid_serializer.rs:14:1 - | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which requires computing whether `my_format::description::{opaque#0}` is freeze... - = note: ...which requires evaluating trait selection obligation `my_format::description::{opaque#0}: core::marker::Freeze`... - = note: ...which again requires computing type of opaque `my_format::description::{opaque#0}`, completing the cycle -note: cycle used when computing type of `my_format::description::{opaque#0}` - --> ../tests/compile-fail/invalid_serializer.rs:14:1 - | -14 | serde::format_description!(my_format, OffsetDateTime, not_string); // string format wrong type - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - = note: this error originates in the macro `serde::format_description` (in Nightly builds, run with -Z macro-backtrace for more info) +14 | serde::format_description!(my_format, OffsetDateTime, not_string); // not in scope + | ^^^^^^^^^^ not found in this scope diff --git a/tests/compile-fail/invalid_time.stderr b/tests/compile-fail/invalid_time.stderr index 303f57327d..8fa41a2b2c 100644 --- a/tests/compile-fail/invalid_time.stderr +++ b/tests/compile-fail/invalid_time.stderr @@ -1,41 +1,41 @@ error: invalid component: hour was 24 - --> $DIR/invalid_time.rs:4:19 + --> ../tests/compile-fail/invalid_time.rs:4:19 | 4 | let _ = time!(24:00); | ^^ error: invalid component: minute was 60 - --> $DIR/invalid_time.rs:5:21 + --> ../tests/compile-fail/invalid_time.rs:5:21 | 5 | let _ = time!(0:60); | ^^ error: invalid component: second was 60 - --> $DIR/invalid_time.rs:6:24 + --> ../tests/compile-fail/invalid_time.rs:6:24 | 6 | let _ = time!(0:00:60); | ^^ error: unexpected token: x - --> $DIR/invalid_time.rs:7:19 + --> ../tests/compile-fail/invalid_time.rs:7:19 | 7 | let _ = time!(x); | ^ error: unexpected token: x - --> $DIR/invalid_time.rs:8:27 + --> ../tests/compile-fail/invalid_time.rs:8:27 | 8 | let _ = time!(0:00:00 x); | ^ error: invalid component: hour was "" - --> $DIR/invalid_time.rs:9:19 + --> ../tests/compile-fail/invalid_time.rs:9:19 | 9 | let _ = time!(""); | ^^ error: unexpected end of input - --> $DIR/invalid_time.rs:10:13 + --> ../tests/compile-fail/invalid_time.rs:10:13 | 10 | let _ = time!(0:); | ^^^^^^^^^ @@ -43,25 +43,25 @@ error: unexpected end of input = note: this error originates in the macro `time` (in Nightly builds, run with -Z macro-backtrace for more info) error: unexpected token: , - --> $DIR/invalid_time.rs:11:20 + --> ../tests/compile-fail/invalid_time.rs:11:20 | 11 | let _ = time!(0,); | ^ error: invalid component: second was 0a - --> $DIR/invalid_time.rs:12:24 + --> ../tests/compile-fail/invalid_time.rs:12:24 | 12 | let _ = time!(0:00:0a); | ^^ error: invalid component: hour was 0 - --> $DIR/invalid_time.rs:13:19 + --> ../tests/compile-fail/invalid_time.rs:13:19 | 13 | let _ = time!(0:00 pm); | ^^^^^^^ error: unexpected end of input - --> $DIR/invalid_time.rs:14:13 + --> ../tests/compile-fail/invalid_time.rs:14:13 | 14 | let _ = time!(0); | ^^^^^^^^ @@ -69,13 +69,13 @@ error: unexpected end of input = note: this error originates in the macro `time` (in Nightly builds, run with -Z macro-backtrace for more info) error: invalid component: hour was 0 - --> $DIR/invalid_time.rs:15:19 + --> ../tests/compile-fail/invalid_time.rs:15:19 | 15 | let _ = time!(0 pm); | ^^^^ error: unexpected token: : - --> $DIR/invalid_time.rs:16:24 + --> ../tests/compile-fail/invalid_time.rs:16:24 | 16 | let _ = time!(1 am :); | ^ diff --git a/tests/date.rs b/tests/date.rs index 74ab27db01..166447c15c 100644 --- a/tests/date.rs +++ b/tests/date.rs @@ -7,7 +7,7 @@ use time::{util, Date, Duration, Month, Weekday}; #[test] fn debug() { - assert_eq!(format!("{:?}", date!(2020 - 02 - 03)), "2020-02-03"); + assert_eq!(format!("{:?}", date!(2020-02-03)), "2020-02-03"); } #[test] @@ -39,436 +39,436 @@ fn weeks_in_year_exhaustive() { #[test] fn test_monday_based_week_dominical_a() { - assert_eq!(date!(2023 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2023 - 01 - 02).monday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2023-01-01).monday_based_week(), 0); + assert_eq!(date!(2023-01-02).monday_based_week(), 1); + assert_eq!(date!(2023-01-03).monday_based_week(), 1); + assert_eq!(date!(2023-01-04).monday_based_week(), 1); + assert_eq!(date!(2023-01-05).monday_based_week(), 1); + assert_eq!(date!(2023-01-06).monday_based_week(), 1); + assert_eq!(date!(2023-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_b() { - assert_eq!(date!(2022 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2022 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2022 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2022-01-01).monday_based_week(), 0); + assert_eq!(date!(2022-01-02).monday_based_week(), 0); + assert_eq!(date!(2022-01-03).monday_based_week(), 1); + assert_eq!(date!(2022-01-04).monday_based_week(), 1); + assert_eq!(date!(2022-01-05).monday_based_week(), 1); + assert_eq!(date!(2022-01-06).monday_based_week(), 1); + assert_eq!(date!(2022-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_c() { - assert_eq!(date!(2021 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2021 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2021 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2021 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2021-01-01).monday_based_week(), 0); + assert_eq!(date!(2021-01-02).monday_based_week(), 0); + assert_eq!(date!(2021-01-03).monday_based_week(), 0); + assert_eq!(date!(2021-01-04).monday_based_week(), 1); + assert_eq!(date!(2021-01-05).monday_based_week(), 1); + assert_eq!(date!(2021-01-06).monday_based_week(), 1); + assert_eq!(date!(2021-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_d() { - assert_eq!(date!(2026 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2026 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2026 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2026-01-01).monday_based_week(), 0); + assert_eq!(date!(2026-01-02).monday_based_week(), 0); + assert_eq!(date!(2026-01-03).monday_based_week(), 0); + assert_eq!(date!(2026-01-04).monday_based_week(), 0); + assert_eq!(date!(2026-01-05).monday_based_week(), 1); + assert_eq!(date!(2026-01-06).monday_based_week(), 1); + assert_eq!(date!(2026-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_e() { - assert_eq!(date!(2025 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 05).monday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2025 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2025-01-01).monday_based_week(), 0); + assert_eq!(date!(2025-01-02).monday_based_week(), 0); + assert_eq!(date!(2025-01-03).monday_based_week(), 0); + assert_eq!(date!(2025-01-04).monday_based_week(), 0); + assert_eq!(date!(2025-01-05).monday_based_week(), 0); + assert_eq!(date!(2025-01-06).monday_based_week(), 1); + assert_eq!(date!(2025-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_f() { - assert_eq!(date!(2019 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 05).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 06).monday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2019-01-01).monday_based_week(), 0); + assert_eq!(date!(2019-01-02).monday_based_week(), 0); + assert_eq!(date!(2019-01-03).monday_based_week(), 0); + assert_eq!(date!(2019-01-04).monday_based_week(), 0); + assert_eq!(date!(2019-01-05).monday_based_week(), 0); + assert_eq!(date!(2019-01-06).monday_based_week(), 0); + assert_eq!(date!(2019-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_g() { - assert_eq!(date!(2018 - 01 - 01).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 02).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2018 - 01 - 07).monday_based_week(), 1); + assert_eq!(date!(2018-01-01).monday_based_week(), 1); + assert_eq!(date!(2018-01-02).monday_based_week(), 1); + assert_eq!(date!(2018-01-03).monday_based_week(), 1); + assert_eq!(date!(2018-01-04).monday_based_week(), 1); + assert_eq!(date!(2018-01-05).monday_based_week(), 1); + assert_eq!(date!(2018-01-06).monday_based_week(), 1); + assert_eq!(date!(2018-01-07).monday_based_week(), 1); } #[test] fn test_monday_based_week_dominical_ag() { - assert_eq!(date!(2012 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2012 - 01 - 02).monday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2012 - 02 - 28).monday_based_week(), 9); - assert_eq!(date!(2012 - 02 - 29).monday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 01).monday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 05).monday_based_week(), 10); - assert_eq!(date!(2012 - 03 - 06).monday_based_week(), 10); - assert_eq!(date!(2012 - 03 - 07).monday_based_week(), 10); + assert_eq!(date!(2012-01-01).monday_based_week(), 0); + assert_eq!(date!(2012-01-02).monday_based_week(), 1); + assert_eq!(date!(2012-01-03).monday_based_week(), 1); + assert_eq!(date!(2012-01-04).monday_based_week(), 1); + assert_eq!(date!(2012-01-05).monday_based_week(), 1); + assert_eq!(date!(2012-01-06).monday_based_week(), 1); + assert_eq!(date!(2012-01-07).monday_based_week(), 1); + assert_eq!(date!(2012-02-28).monday_based_week(), 9); + assert_eq!(date!(2012-02-29).monday_based_week(), 9); + assert_eq!(date!(2012-03-01).monday_based_week(), 9); + assert_eq!(date!(2012-03-02).monday_based_week(), 9); + assert_eq!(date!(2012-03-03).monday_based_week(), 9); + assert_eq!(date!(2012-03-04).monday_based_week(), 9); + assert_eq!(date!(2012-03-05).monday_based_week(), 10); + assert_eq!(date!(2012-03-06).monday_based_week(), 10); + assert_eq!(date!(2012-03-07).monday_based_week(), 10); } #[test] fn test_monday_based_week_dominical_ba() { - assert_eq!(date!(2028 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2028 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2028 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2028 - 02 - 28).monday_based_week(), 9); - assert_eq!(date!(2028 - 02 - 29).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 01).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 05).monday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 06).monday_based_week(), 10); - assert_eq!(date!(2028 - 03 - 07).monday_based_week(), 10); + assert_eq!(date!(2028-01-01).monday_based_week(), 0); + assert_eq!(date!(2028-01-02).monday_based_week(), 0); + assert_eq!(date!(2028-01-03).monday_based_week(), 1); + assert_eq!(date!(2028-01-04).monday_based_week(), 1); + assert_eq!(date!(2028-01-05).monday_based_week(), 1); + assert_eq!(date!(2028-01-06).monday_based_week(), 1); + assert_eq!(date!(2028-01-07).monday_based_week(), 1); + assert_eq!(date!(2028-02-28).monday_based_week(), 9); + assert_eq!(date!(2028-02-29).monday_based_week(), 9); + assert_eq!(date!(2028-03-01).monday_based_week(), 9); + assert_eq!(date!(2028-03-02).monday_based_week(), 9); + assert_eq!(date!(2028-03-03).monday_based_week(), 9); + assert_eq!(date!(2028-03-04).monday_based_week(), 9); + assert_eq!(date!(2028-03-05).monday_based_week(), 9); + assert_eq!(date!(2028-03-06).monday_based_week(), 10); + assert_eq!(date!(2028-03-07).monday_based_week(), 10); } #[test] fn test_monday_based_week_dominical_cb() { - assert_eq!(date!(2016 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2016 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2016 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2016 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2016 - 02 - 28).monday_based_week(), 8); - assert_eq!(date!(2016 - 02 - 29).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 01).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 05).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 06).monday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 07).monday_based_week(), 10); + assert_eq!(date!(2016-01-01).monday_based_week(), 0); + assert_eq!(date!(2016-01-02).monday_based_week(), 0); + assert_eq!(date!(2016-01-03).monday_based_week(), 0); + assert_eq!(date!(2016-01-04).monday_based_week(), 1); + assert_eq!(date!(2016-01-05).monday_based_week(), 1); + assert_eq!(date!(2016-01-06).monday_based_week(), 1); + assert_eq!(date!(2016-01-07).monday_based_week(), 1); + assert_eq!(date!(2016-02-28).monday_based_week(), 8); + assert_eq!(date!(2016-02-29).monday_based_week(), 9); + assert_eq!(date!(2016-03-01).monday_based_week(), 9); + assert_eq!(date!(2016-03-02).monday_based_week(), 9); + assert_eq!(date!(2016-03-03).monday_based_week(), 9); + assert_eq!(date!(2016-03-04).monday_based_week(), 9); + assert_eq!(date!(2016-03-05).monday_based_week(), 9); + assert_eq!(date!(2016-03-06).monday_based_week(), 9); + assert_eq!(date!(2016-03-07).monday_based_week(), 10); } #[test] fn test_monday_based_week_dominical_dc() { - assert_eq!(date!(2032 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2032 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2032 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2032 - 02 - 28).monday_based_week(), 8); - assert_eq!(date!(2032 - 02 - 29).monday_based_week(), 8); - assert_eq!(date!(2032 - 03 - 01).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 05).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 06).monday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 07).monday_based_week(), 9); + assert_eq!(date!(2032-01-01).monday_based_week(), 0); + assert_eq!(date!(2032-01-02).monday_based_week(), 0); + assert_eq!(date!(2032-01-03).monday_based_week(), 0); + assert_eq!(date!(2032-01-04).monday_based_week(), 0); + assert_eq!(date!(2032-01-05).monday_based_week(), 1); + assert_eq!(date!(2032-01-06).monday_based_week(), 1); + assert_eq!(date!(2032-01-07).monday_based_week(), 1); + assert_eq!(date!(2032-02-28).monday_based_week(), 8); + assert_eq!(date!(2032-02-29).monday_based_week(), 8); + assert_eq!(date!(2032-03-01).monday_based_week(), 9); + assert_eq!(date!(2032-03-02).monday_based_week(), 9); + assert_eq!(date!(2032-03-03).monday_based_week(), 9); + assert_eq!(date!(2032-03-04).monday_based_week(), 9); + assert_eq!(date!(2032-03-05).monday_based_week(), 9); + assert_eq!(date!(2032-03-06).monday_based_week(), 9); + assert_eq!(date!(2032-03-07).monday_based_week(), 9); } #[test] fn test_monday_based_week_dominical_ed() { - assert_eq!(date!(2020 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 05).monday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2020 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2020 - 02 - 28).monday_based_week(), 8); - assert_eq!(date!(2020 - 02 - 29).monday_based_week(), 8); - assert_eq!(date!(2020 - 03 - 01).monday_based_week(), 8); - assert_eq!(date!(2020 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 05).monday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 06).monday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 07).monday_based_week(), 9); + assert_eq!(date!(2020-01-01).monday_based_week(), 0); + assert_eq!(date!(2020-01-02).monday_based_week(), 0); + assert_eq!(date!(2020-01-03).monday_based_week(), 0); + assert_eq!(date!(2020-01-04).monday_based_week(), 0); + assert_eq!(date!(2020-01-05).monday_based_week(), 0); + assert_eq!(date!(2020-01-06).monday_based_week(), 1); + assert_eq!(date!(2020-01-07).monday_based_week(), 1); + assert_eq!(date!(2020-02-28).monday_based_week(), 8); + assert_eq!(date!(2020-02-29).monday_based_week(), 8); + assert_eq!(date!(2020-03-01).monday_based_week(), 8); + assert_eq!(date!(2020-03-02).monday_based_week(), 9); + assert_eq!(date!(2020-03-03).monday_based_week(), 9); + assert_eq!(date!(2020-03-04).monday_based_week(), 9); + assert_eq!(date!(2020-03-05).monday_based_week(), 9); + assert_eq!(date!(2020-03-06).monday_based_week(), 9); + assert_eq!(date!(2020-03-07).monday_based_week(), 9); } #[test] fn test_monday_based_week_dominical_fe() { - assert_eq!(date!(2036 - 01 - 01).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 02).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 03).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 04).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 05).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 06).monday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2036 - 02 - 28).monday_based_week(), 8); - assert_eq!(date!(2036 - 02 - 29).monday_based_week(), 8); - assert_eq!(date!(2036 - 03 - 01).monday_based_week(), 8); - assert_eq!(date!(2036 - 03 - 02).monday_based_week(), 8); - assert_eq!(date!(2036 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 04).monday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 05).monday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 06).monday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 07).monday_based_week(), 9); + assert_eq!(date!(2036-01-01).monday_based_week(), 0); + assert_eq!(date!(2036-01-02).monday_based_week(), 0); + assert_eq!(date!(2036-01-03).monday_based_week(), 0); + assert_eq!(date!(2036-01-04).monday_based_week(), 0); + assert_eq!(date!(2036-01-05).monday_based_week(), 0); + assert_eq!(date!(2036-01-06).monday_based_week(), 0); + assert_eq!(date!(2036-01-07).monday_based_week(), 1); + assert_eq!(date!(2036-02-28).monday_based_week(), 8); + assert_eq!(date!(2036-02-29).monday_based_week(), 8); + assert_eq!(date!(2036-03-01).monday_based_week(), 8); + assert_eq!(date!(2036-03-02).monday_based_week(), 8); + assert_eq!(date!(2036-03-03).monday_based_week(), 9); + assert_eq!(date!(2036-03-04).monday_based_week(), 9); + assert_eq!(date!(2036-03-05).monday_based_week(), 9); + assert_eq!(date!(2036-03-06).monday_based_week(), 9); + assert_eq!(date!(2036-03-07).monday_based_week(), 9); } #[test] fn test_monday_based_week_dominical_gf() { - assert_eq!(date!(2024 - 01 - 01).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 02).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 03).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 04).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 05).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 06).monday_based_week(), 1); - assert_eq!(date!(2024 - 01 - 07).monday_based_week(), 1); - assert_eq!(date!(2024 - 02 - 28).monday_based_week(), 9); - assert_eq!(date!(2024 - 02 - 29).monday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 01).monday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 02).monday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 03).monday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 04).monday_based_week(), 10); - assert_eq!(date!(2024 - 03 - 05).monday_based_week(), 10); - assert_eq!(date!(2024 - 03 - 06).monday_based_week(), 10); - assert_eq!(date!(2024 - 03 - 07).monday_based_week(), 10); + assert_eq!(date!(2024-01-01).monday_based_week(), 1); + assert_eq!(date!(2024-01-02).monday_based_week(), 1); + assert_eq!(date!(2024-01-03).monday_based_week(), 1); + assert_eq!(date!(2024-01-04).monday_based_week(), 1); + assert_eq!(date!(2024-01-05).monday_based_week(), 1); + assert_eq!(date!(2024-01-06).monday_based_week(), 1); + assert_eq!(date!(2024-01-07).monday_based_week(), 1); + assert_eq!(date!(2024-02-28).monday_based_week(), 9); + assert_eq!(date!(2024-02-29).monday_based_week(), 9); + assert_eq!(date!(2024-03-01).monday_based_week(), 9); + assert_eq!(date!(2024-03-02).monday_based_week(), 9); + assert_eq!(date!(2024-03-03).monday_based_week(), 9); + assert_eq!(date!(2024-03-04).monday_based_week(), 10); + assert_eq!(date!(2024-03-05).monday_based_week(), 10); + assert_eq!(date!(2024-03-06).monday_based_week(), 10); + assert_eq!(date!(2024-03-07).monday_based_week(), 10); } #[test] fn test_sunday_based_week_dominical_a() { - assert_eq!(date!(2023 - 01 - 01).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 02).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2023 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2023-01-01).sunday_based_week(), 1); + assert_eq!(date!(2023-01-02).sunday_based_week(), 1); + assert_eq!(date!(2023-01-03).sunday_based_week(), 1); + assert_eq!(date!(2023-01-04).sunday_based_week(), 1); + assert_eq!(date!(2023-01-05).sunday_based_week(), 1); + assert_eq!(date!(2023-01-06).sunday_based_week(), 1); + assert_eq!(date!(2023-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_b() { - assert_eq!(date!(2022 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2022 - 01 - 02).sunday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2022 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2022-01-01).sunday_based_week(), 0); + assert_eq!(date!(2022-01-02).sunday_based_week(), 1); + assert_eq!(date!(2022-01-03).sunday_based_week(), 1); + assert_eq!(date!(2022-01-04).sunday_based_week(), 1); + assert_eq!(date!(2022-01-05).sunday_based_week(), 1); + assert_eq!(date!(2022-01-06).sunday_based_week(), 1); + assert_eq!(date!(2022-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_c() { - assert_eq!(date!(2021 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2021 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2021 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2021 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2021-01-01).sunday_based_week(), 0); + assert_eq!(date!(2021-01-02).sunday_based_week(), 0); + assert_eq!(date!(2021-01-03).sunday_based_week(), 1); + assert_eq!(date!(2021-01-04).sunday_based_week(), 1); + assert_eq!(date!(2021-01-05).sunday_based_week(), 1); + assert_eq!(date!(2021-01-06).sunday_based_week(), 1); + assert_eq!(date!(2021-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_d() { - assert_eq!(date!(2026 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2026 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2026 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2026 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2026 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2026-01-01).sunday_based_week(), 0); + assert_eq!(date!(2026-01-02).sunday_based_week(), 0); + assert_eq!(date!(2026-01-03).sunday_based_week(), 0); + assert_eq!(date!(2026-01-04).sunday_based_week(), 1); + assert_eq!(date!(2026-01-05).sunday_based_week(), 1); + assert_eq!(date!(2026-01-06).sunday_based_week(), 1); + assert_eq!(date!(2026-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_e() { - assert_eq!(date!(2025 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2025 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2025 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2025 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2025-01-01).sunday_based_week(), 0); + assert_eq!(date!(2025-01-02).sunday_based_week(), 0); + assert_eq!(date!(2025-01-03).sunday_based_week(), 0); + assert_eq!(date!(2025-01-04).sunday_based_week(), 0); + assert_eq!(date!(2025-01-05).sunday_based_week(), 1); + assert_eq!(date!(2025-01-06).sunday_based_week(), 1); + assert_eq!(date!(2025-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_f() { - assert_eq!(date!(2019 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 05).sunday_based_week(), 0); - assert_eq!(date!(2019 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2019 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2019-01-01).sunday_based_week(), 0); + assert_eq!(date!(2019-01-02).sunday_based_week(), 0); + assert_eq!(date!(2019-01-03).sunday_based_week(), 0); + assert_eq!(date!(2019-01-04).sunday_based_week(), 0); + assert_eq!(date!(2019-01-05).sunday_based_week(), 0); + assert_eq!(date!(2019-01-06).sunday_based_week(), 1); + assert_eq!(date!(2019-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_g() { - assert_eq!(date!(2018 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 05).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 06).sunday_based_week(), 0); - assert_eq!(date!(2018 - 01 - 07).sunday_based_week(), 1); + assert_eq!(date!(2018-01-01).sunday_based_week(), 0); + assert_eq!(date!(2018-01-02).sunday_based_week(), 0); + assert_eq!(date!(2018-01-03).sunday_based_week(), 0); + assert_eq!(date!(2018-01-04).sunday_based_week(), 0); + assert_eq!(date!(2018-01-05).sunday_based_week(), 0); + assert_eq!(date!(2018-01-06).sunday_based_week(), 0); + assert_eq!(date!(2018-01-07).sunday_based_week(), 1); } #[test] fn test_sunday_based_week_dominical_ag() { - assert_eq!(date!(2012 - 01 - 01).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 02).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2012 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2012 - 02 - 28).sunday_based_week(), 9); - assert_eq!(date!(2012 - 02 - 29).sunday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 01).sunday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2012 - 03 - 04).sunday_based_week(), 10); - assert_eq!(date!(2012 - 03 - 05).sunday_based_week(), 10); - assert_eq!(date!(2012 - 03 - 06).sunday_based_week(), 10); - assert_eq!(date!(2012 - 03 - 07).sunday_based_week(), 10); + assert_eq!(date!(2012-01-01).sunday_based_week(), 1); + assert_eq!(date!(2012-01-02).sunday_based_week(), 1); + assert_eq!(date!(2012-01-03).sunday_based_week(), 1); + assert_eq!(date!(2012-01-04).sunday_based_week(), 1); + assert_eq!(date!(2012-01-05).sunday_based_week(), 1); + assert_eq!(date!(2012-01-06).sunday_based_week(), 1); + assert_eq!(date!(2012-01-07).sunday_based_week(), 1); + assert_eq!(date!(2012-02-28).sunday_based_week(), 9); + assert_eq!(date!(2012-02-29).sunday_based_week(), 9); + assert_eq!(date!(2012-03-01).sunday_based_week(), 9); + assert_eq!(date!(2012-03-02).sunday_based_week(), 9); + assert_eq!(date!(2012-03-03).sunday_based_week(), 9); + assert_eq!(date!(2012-03-04).sunday_based_week(), 10); + assert_eq!(date!(2012-03-05).sunday_based_week(), 10); + assert_eq!(date!(2012-03-06).sunday_based_week(), 10); + assert_eq!(date!(2012-03-07).sunday_based_week(), 10); } #[test] fn test_sunday_based_week_dominical_ba() { - assert_eq!(date!(2028 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2028 - 01 - 02).sunday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2028 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2028 - 02 - 28).sunday_based_week(), 9); - assert_eq!(date!(2028 - 02 - 29).sunday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 01).sunday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2028 - 03 - 05).sunday_based_week(), 10); - assert_eq!(date!(2028 - 03 - 06).sunday_based_week(), 10); - assert_eq!(date!(2028 - 03 - 07).sunday_based_week(), 10); + assert_eq!(date!(2028-01-01).sunday_based_week(), 0); + assert_eq!(date!(2028-01-02).sunday_based_week(), 1); + assert_eq!(date!(2028-01-03).sunday_based_week(), 1); + assert_eq!(date!(2028-01-04).sunday_based_week(), 1); + assert_eq!(date!(2028-01-05).sunday_based_week(), 1); + assert_eq!(date!(2028-01-06).sunday_based_week(), 1); + assert_eq!(date!(2028-01-07).sunday_based_week(), 1); + assert_eq!(date!(2028-02-28).sunday_based_week(), 9); + assert_eq!(date!(2028-02-29).sunday_based_week(), 9); + assert_eq!(date!(2028-03-01).sunday_based_week(), 9); + assert_eq!(date!(2028-03-02).sunday_based_week(), 9); + assert_eq!(date!(2028-03-03).sunday_based_week(), 9); + assert_eq!(date!(2028-03-04).sunday_based_week(), 9); + assert_eq!(date!(2028-03-05).sunday_based_week(), 10); + assert_eq!(date!(2028-03-06).sunday_based_week(), 10); + assert_eq!(date!(2028-03-07).sunday_based_week(), 10); } #[test] fn test_sunday_based_week_dominical_cb() { - assert_eq!(date!(2016 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2016 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2016 - 01 - 03).sunday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2016 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2016 - 02 - 28).sunday_based_week(), 9); - assert_eq!(date!(2016 - 02 - 29).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 01).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 05).sunday_based_week(), 9); - assert_eq!(date!(2016 - 03 - 06).sunday_based_week(), 10); - assert_eq!(date!(2016 - 03 - 07).sunday_based_week(), 10); + assert_eq!(date!(2016-01-01).sunday_based_week(), 0); + assert_eq!(date!(2016-01-02).sunday_based_week(), 0); + assert_eq!(date!(2016-01-03).sunday_based_week(), 1); + assert_eq!(date!(2016-01-04).sunday_based_week(), 1); + assert_eq!(date!(2016-01-05).sunday_based_week(), 1); + assert_eq!(date!(2016-01-06).sunday_based_week(), 1); + assert_eq!(date!(2016-01-07).sunday_based_week(), 1); + assert_eq!(date!(2016-02-28).sunday_based_week(), 9); + assert_eq!(date!(2016-02-29).sunday_based_week(), 9); + assert_eq!(date!(2016-03-01).sunday_based_week(), 9); + assert_eq!(date!(2016-03-02).sunday_based_week(), 9); + assert_eq!(date!(2016-03-03).sunday_based_week(), 9); + assert_eq!(date!(2016-03-04).sunday_based_week(), 9); + assert_eq!(date!(2016-03-05).sunday_based_week(), 9); + assert_eq!(date!(2016-03-06).sunday_based_week(), 10); + assert_eq!(date!(2016-03-07).sunday_based_week(), 10); } #[test] fn test_sunday_based_week_dominical_dc() { - assert_eq!(date!(2032 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2032 - 01 - 04).sunday_based_week(), 1); - assert_eq!(date!(2032 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2032 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2032 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2032 - 02 - 28).sunday_based_week(), 8); - assert_eq!(date!(2032 - 02 - 29).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 01).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 05).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 06).sunday_based_week(), 9); - assert_eq!(date!(2032 - 03 - 07).sunday_based_week(), 10); + assert_eq!(date!(2032-01-01).sunday_based_week(), 0); + assert_eq!(date!(2032-01-02).sunday_based_week(), 0); + assert_eq!(date!(2032-01-03).sunday_based_week(), 0); + assert_eq!(date!(2032-01-04).sunday_based_week(), 1); + assert_eq!(date!(2032-01-05).sunday_based_week(), 1); + assert_eq!(date!(2032-01-06).sunday_based_week(), 1); + assert_eq!(date!(2032-01-07).sunday_based_week(), 1); + assert_eq!(date!(2032-02-28).sunday_based_week(), 8); + assert_eq!(date!(2032-02-29).sunday_based_week(), 9); + assert_eq!(date!(2032-03-01).sunday_based_week(), 9); + assert_eq!(date!(2032-03-02).sunday_based_week(), 9); + assert_eq!(date!(2032-03-03).sunday_based_week(), 9); + assert_eq!(date!(2032-03-04).sunday_based_week(), 9); + assert_eq!(date!(2032-03-05).sunday_based_week(), 9); + assert_eq!(date!(2032-03-06).sunday_based_week(), 9); + assert_eq!(date!(2032-03-07).sunday_based_week(), 10); } #[test] fn test_sunday_based_week_dominical_ed() { - assert_eq!(date!(2020 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2020 - 01 - 05).sunday_based_week(), 1); - assert_eq!(date!(2020 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2020 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2020 - 02 - 28).sunday_based_week(), 8); - assert_eq!(date!(2020 - 02 - 29).sunday_based_week(), 8); - assert_eq!(date!(2020 - 03 - 01).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 05).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 06).sunday_based_week(), 9); - assert_eq!(date!(2020 - 03 - 07).sunday_based_week(), 9); + assert_eq!(date!(2020-01-01).sunday_based_week(), 0); + assert_eq!(date!(2020-01-02).sunday_based_week(), 0); + assert_eq!(date!(2020-01-03).sunday_based_week(), 0); + assert_eq!(date!(2020-01-04).sunday_based_week(), 0); + assert_eq!(date!(2020-01-05).sunday_based_week(), 1); + assert_eq!(date!(2020-01-06).sunday_based_week(), 1); + assert_eq!(date!(2020-01-07).sunday_based_week(), 1); + assert_eq!(date!(2020-02-28).sunday_based_week(), 8); + assert_eq!(date!(2020-02-29).sunday_based_week(), 8); + assert_eq!(date!(2020-03-01).sunday_based_week(), 9); + assert_eq!(date!(2020-03-02).sunday_based_week(), 9); + assert_eq!(date!(2020-03-03).sunday_based_week(), 9); + assert_eq!(date!(2020-03-04).sunday_based_week(), 9); + assert_eq!(date!(2020-03-05).sunday_based_week(), 9); + assert_eq!(date!(2020-03-06).sunday_based_week(), 9); + assert_eq!(date!(2020-03-07).sunday_based_week(), 9); } #[test] fn test_sunday_based_week_dominical_fe() { - assert_eq!(date!(2036 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 05).sunday_based_week(), 0); - assert_eq!(date!(2036 - 01 - 06).sunday_based_week(), 1); - assert_eq!(date!(2036 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2036 - 02 - 28).sunday_based_week(), 8); - assert_eq!(date!(2036 - 02 - 29).sunday_based_week(), 8); - assert_eq!(date!(2036 - 03 - 01).sunday_based_week(), 8); - assert_eq!(date!(2036 - 03 - 02).sunday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 05).sunday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 06).sunday_based_week(), 9); - assert_eq!(date!(2036 - 03 - 07).sunday_based_week(), 9); + assert_eq!(date!(2036-01-01).sunday_based_week(), 0); + assert_eq!(date!(2036-01-02).sunday_based_week(), 0); + assert_eq!(date!(2036-01-03).sunday_based_week(), 0); + assert_eq!(date!(2036-01-04).sunday_based_week(), 0); + assert_eq!(date!(2036-01-05).sunday_based_week(), 0); + assert_eq!(date!(2036-01-06).sunday_based_week(), 1); + assert_eq!(date!(2036-01-07).sunday_based_week(), 1); + assert_eq!(date!(2036-02-28).sunday_based_week(), 8); + assert_eq!(date!(2036-02-29).sunday_based_week(), 8); + assert_eq!(date!(2036-03-01).sunday_based_week(), 8); + assert_eq!(date!(2036-03-02).sunday_based_week(), 9); + assert_eq!(date!(2036-03-03).sunday_based_week(), 9); + assert_eq!(date!(2036-03-04).sunday_based_week(), 9); + assert_eq!(date!(2036-03-05).sunday_based_week(), 9); + assert_eq!(date!(2036-03-06).sunday_based_week(), 9); + assert_eq!(date!(2036-03-07).sunday_based_week(), 9); } #[test] fn test_sunday_based_week_dominical_gf() { - assert_eq!(date!(2024 - 01 - 01).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 02).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 03).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 04).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 05).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 06).sunday_based_week(), 0); - assert_eq!(date!(2024 - 01 - 07).sunday_based_week(), 1); - assert_eq!(date!(2024 - 02 - 28).sunday_based_week(), 8); - assert_eq!(date!(2024 - 02 - 29).sunday_based_week(), 8); - assert_eq!(date!(2024 - 03 - 01).sunday_based_week(), 8); - assert_eq!(date!(2024 - 03 - 02).sunday_based_week(), 8); - assert_eq!(date!(2024 - 03 - 03).sunday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 04).sunday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 05).sunday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 06).sunday_based_week(), 9); - assert_eq!(date!(2024 - 03 - 07).sunday_based_week(), 9); + assert_eq!(date!(2024-01-01).sunday_based_week(), 0); + assert_eq!(date!(2024-01-02).sunday_based_week(), 0); + assert_eq!(date!(2024-01-03).sunday_based_week(), 0); + assert_eq!(date!(2024-01-04).sunday_based_week(), 0); + assert_eq!(date!(2024-01-05).sunday_based_week(), 0); + assert_eq!(date!(2024-01-06).sunday_based_week(), 0); + assert_eq!(date!(2024-01-07).sunday_based_week(), 1); + assert_eq!(date!(2024-02-28).sunday_based_week(), 8); + assert_eq!(date!(2024-02-29).sunday_based_week(), 8); + assert_eq!(date!(2024-03-01).sunday_based_week(), 8); + assert_eq!(date!(2024-03-02).sunday_based_week(), 8); + assert_eq!(date!(2024-03-03).sunday_based_week(), 9); + assert_eq!(date!(2024-03-04).sunday_based_week(), 9); + assert_eq!(date!(2024-03-05).sunday_based_week(), 9); + assert_eq!(date!(2024-03-06).sunday_based_week(), 9); + assert_eq!(date!(2024-03-07).sunday_based_week(), 9); } #[test] @@ -483,172 +483,133 @@ fn from_iso_week_date() { // Regression test. Year zero (1 BCE) has dominical letter BA. assert_eq!( Date::from_iso_week_date(-1, 52, Saturday), - Ok(date!(0000 - 01 - 01)) + Ok(date!(0000-01-01)) ); - assert_eq!(date!(-0001-W 52-6), date!(0000 - 01 - 01)); + assert_eq!(date!(-0001-W 52-6), date!(0000-01-01)); } #[test] fn year() { - assert_eq!(date!(2019 - 002).year(), 2019); - assert_eq!(date!(2020 - 002).year(), 2020); + assert_eq!(date!(2019-002).year(), 2019); + assert_eq!(date!(2020-002).year(), 2020); } #[test] fn month() { - assert_eq!(date!(2019 - 002).month(), Month::January); - assert_eq!(date!(2020 - 002).month(), Month::January); - assert_eq!(date!(2019 - 060).month(), Month::March); - assert_eq!(date!(2020 - 060).month(), Month::February); + assert_eq!(date!(2019-002).month(), Month::January); + assert_eq!(date!(2020-002).month(), Month::January); + assert_eq!(date!(2019-060).month(), Month::March); + assert_eq!(date!(2020-060).month(), Month::February); } #[test] fn day() { - assert_eq!(date!(2019 - 002).day(), 2); - assert_eq!(date!(2020 - 002).day(), 2); - assert_eq!(date!(2019 - 060).day(), 1); - assert_eq!(date!(2020 - 060).day(), 29); + assert_eq!(date!(2019-002).day(), 2); + assert_eq!(date!(2020-002).day(), 2); + assert_eq!(date!(2019-060).day(), 1); + assert_eq!(date!(2020-060).day(), 29); } #[test] fn iso_week() { - assert_eq!(date!(2019 - 01 - 01).iso_week(), 1); - assert_eq!(date!(2019 - 10 - 04).iso_week(), 40); - assert_eq!(date!(2020 - 01 - 01).iso_week(), 1); - assert_eq!(date!(2020 - 12 - 31).iso_week(), 53); - assert_eq!(date!(2021 - 01 - 01).iso_week(), 53); + assert_eq!(date!(2019-01-01).iso_week(), 1); + assert_eq!(date!(2019-10-04).iso_week(), 40); + assert_eq!(date!(2020-01-01).iso_week(), 1); + assert_eq!(date!(2020-12-31).iso_week(), 53); + assert_eq!(date!(2021-01-01).iso_week(), 53); } #[test] fn to_calendar_date() { assert_eq!( - date!(2019 - 01 - 02).to_calendar_date(), + date!(2019-01-02).to_calendar_date(), (2019, Month::January, 2) ); assert_eq!( - date!(2019 - 02 - 02).to_calendar_date(), + date!(2019-02-02).to_calendar_date(), (2019, Month::February, 2) ); assert_eq!( - date!(2019 - 03 - 02).to_calendar_date(), + date!(2019-03-02).to_calendar_date(), (2019, Month::March, 2) ); assert_eq!( - date!(2019 - 04 - 02).to_calendar_date(), + date!(2019-04-02).to_calendar_date(), (2019, Month::April, 2) ); + assert_eq!(date!(2019-05-02).to_calendar_date(), (2019, Month::May, 2)); + assert_eq!(date!(2019-06-02).to_calendar_date(), (2019, Month::June, 2)); + assert_eq!(date!(2019-07-02).to_calendar_date(), (2019, Month::July, 2)); assert_eq!( - date!(2019 - 05 - 02).to_calendar_date(), - (2019, Month::May, 2) - ); - assert_eq!( - date!(2019 - 06 - 02).to_calendar_date(), - (2019, Month::June, 2) - ); - assert_eq!( - date!(2019 - 07 - 02).to_calendar_date(), - (2019, Month::July, 2) - ); - assert_eq!( - date!(2019 - 08 - 02).to_calendar_date(), + date!(2019-08-02).to_calendar_date(), (2019, Month::August, 2) ); assert_eq!( - date!(2019 - 09 - 02).to_calendar_date(), + date!(2019-09-02).to_calendar_date(), (2019, Month::September, 2) ); assert_eq!( - date!(2019 - 10 - 02).to_calendar_date(), + date!(2019-10-02).to_calendar_date(), (2019, Month::October, 2) ); assert_eq!( - date!(2019 - 11 - 02).to_calendar_date(), + date!(2019-11-02).to_calendar_date(), (2019, Month::November, 2) ); assert_eq!( - date!(2019 - 12 - 02).to_calendar_date(), + date!(2019-12-02).to_calendar_date(), (2019, Month::December, 2) ); } #[test] fn to_ordinal_date() { - assert_eq!(date!(2019 - 01 - 01).to_ordinal_date(), (2019, 1)); + assert_eq!(date!(2019-01-01).to_ordinal_date(), (2019, 1)); } #[test] fn to_iso_week_date() { use Weekday::*; - assert_eq!(date!(2019 - 01 - 01).to_iso_week_date(), (2019, 1, Tuesday)); - assert_eq!(date!(2019 - 10 - 04).to_iso_week_date(), (2019, 40, Friday)); - assert_eq!( - date!(2020 - 01 - 01).to_iso_week_date(), - (2020, 1, Wednesday) - ); - assert_eq!( - date!(2020 - 12 - 31).to_iso_week_date(), - (2020, 53, Thursday) - ); - assert_eq!(date!(2021 - 01 - 01).to_iso_week_date(), (2020, 53, Friday)); - assert_eq!(date!(0000 - 01 - 01).to_iso_week_date(), (-1, 52, Saturday)); + assert_eq!(date!(2019-01-01).to_iso_week_date(), (2019, 1, Tuesday)); + assert_eq!(date!(2019-10-04).to_iso_week_date(), (2019, 40, Friday)); + assert_eq!(date!(2020-01-01).to_iso_week_date(), (2020, 1, Wednesday)); + assert_eq!(date!(2020-12-31).to_iso_week_date(), (2020, 53, Thursday)); + assert_eq!(date!(2021-01-01).to_iso_week_date(), (2020, 53, Friday)); + assert_eq!(date!(0000-01-01).to_iso_week_date(), (-1, 52, Saturday)); } #[test] fn weekday() { use Weekday::*; - assert_eq!(date!(2019 - 01 - 01).weekday(), Tuesday); - assert_eq!(date!(2019 - 02 - 01).weekday(), Friday); - assert_eq!(date!(2019 - 03 - 01).weekday(), Friday); - assert_eq!(date!(2019 - 04 - 01).weekday(), Monday); - assert_eq!(date!(2019 - 05 - 01).weekday(), Wednesday); - assert_eq!(date!(2019 - 06 - 01).weekday(), Saturday); - assert_eq!(date!(2019 - 07 - 01).weekday(), Monday); - assert_eq!(date!(2019 - 08 - 01).weekday(), Thursday); - assert_eq!(date!(2019 - 09 - 01).weekday(), Sunday); - assert_eq!(date!(2019 - 10 - 01).weekday(), Tuesday); - assert_eq!(date!(2019 - 11 - 01).weekday(), Friday); - assert_eq!(date!(2019 - 12 - 01).weekday(), Sunday); + assert_eq!(date!(2019-01-01).weekday(), Tuesday); + assert_eq!(date!(2019-02-01).weekday(), Friday); + assert_eq!(date!(2019-03-01).weekday(), Friday); + assert_eq!(date!(2019-04-01).weekday(), Monday); + assert_eq!(date!(2019-05-01).weekday(), Wednesday); + assert_eq!(date!(2019-06-01).weekday(), Saturday); + assert_eq!(date!(2019-07-01).weekday(), Monday); + assert_eq!(date!(2019-08-01).weekday(), Thursday); + assert_eq!(date!(2019-09-01).weekday(), Sunday); + assert_eq!(date!(2019-10-01).weekday(), Tuesday); + assert_eq!(date!(2019-11-01).weekday(), Friday); + assert_eq!(date!(2019-12-01).weekday(), Sunday); } #[test] fn next_day() { - assert_eq!( - date!(2019 - 01 - 01).next_day(), - Some(date!(2019 - 01 - 02)) - ); - assert_eq!( - date!(2019 - 01 - 31).next_day(), - Some(date!(2019 - 02 - 01)) - ); - assert_eq!( - date!(2019 - 12 - 31).next_day(), - Some(date!(2020 - 01 - 01)) - ); - assert_eq!( - date!(2020 - 12 - 31).next_day(), - Some(date!(2021 - 01 - 01)) - ); + assert_eq!(date!(2019-01-01).next_day(), Some(date!(2019-01-02))); + assert_eq!(date!(2019-01-31).next_day(), Some(date!(2019-02-01))); + assert_eq!(date!(2019-12-31).next_day(), Some(date!(2020-01-01))); + assert_eq!(date!(2020-12-31).next_day(), Some(date!(2021-01-01))); assert_eq!(Date::MAX.next_day(), None); } #[test] fn previous_day() { - assert_eq!( - date!(2019 - 01 - 02).previous_day(), - Some(date!(2019 - 01 - 01)) - ); - assert_eq!( - date!(2019 - 02 - 01).previous_day(), - Some(date!(2019 - 01 - 31)) - ); - assert_eq!( - date!(2020 - 01 - 01).previous_day(), - Some(date!(2019 - 12 - 31)) - ); - assert_eq!( - date!(2021 - 01 - 01).previous_day(), - Some(date!(2020 - 12 - 31)) - ); + assert_eq!(date!(2019-01-02).previous_day(), Some(date!(2019-01-01))); + assert_eq!(date!(2019-02-01).previous_day(), Some(date!(2019-01-31))); + assert_eq!(date!(2020-01-01).previous_day(), Some(date!(2019-12-31))); + assert_eq!(date!(2021-01-01).previous_day(), Some(date!(2020-12-31))); assert_eq!(Date::MIN.previous_day(), None); } @@ -657,9 +618,9 @@ fn to_julian_day() { assert_eq!(date!(-999_999 - 01 - 01).to_julian_day(), -363_521_074); assert_eq!(date!(-9999 - 01 - 01).to_julian_day(), -1_930_999); assert_eq!(date!(-4713 - 11 - 24).to_julian_day(), 0); - assert_eq!(date!(2000 - 01 - 01).to_julian_day(), 2_451_545); - assert_eq!(date!(2019 - 01 - 01).to_julian_day(), 2_458_485); - assert_eq!(date!(2019 - 12 - 31).to_julian_day(), 2_458_849); + assert_eq!(date!(2000-01-01).to_julian_day(), 2_451_545); + assert_eq!(date!(2019-01-01).to_julian_day(), 2_458_485); + assert_eq!(date!(2019-12-31).to_julian_day(), 2_458_849); } #[test] @@ -673,21 +634,21 @@ fn from_julian_day() { Ok(date!(-9999 - 01 - 01)) ); assert_eq!(Date::from_julian_day(0), Ok(date!(-4713 - 11 - 24))); - assert_eq!(Date::from_julian_day(2_451_545), Ok(date!(2000 - 01 - 01))); - assert_eq!(Date::from_julian_day(2_458_485), Ok(date!(2019 - 01 - 01))); - assert_eq!(Date::from_julian_day(2_458_849), Ok(date!(2019 - 12 - 31))); + assert_eq!(Date::from_julian_day(2_451_545), Ok(date!(2000-01-01))); + assert_eq!(Date::from_julian_day(2_458_485), Ok(date!(2019-01-01))); + assert_eq!(Date::from_julian_day(2_458_849), Ok(date!(2019-12-31))); assert!(Date::from_julian_day(i32::MAX).is_err()); } #[test] fn midnight() { - assert_eq!(date!(1970 - 01 - 01).midnight(), datetime!(1970-01-01 0:00)); + assert_eq!(date!(1970-01-01).midnight(), datetime!(1970-01-01 0:00)); } #[test] fn with_time() { assert_eq!( - date!(1970 - 01 - 01).with_time(time!(0:00)), + date!(1970-01-01).with_time(time!(0:00)), datetime!(1970-01-01 0:00), ); } @@ -695,101 +656,101 @@ fn with_time() { #[test] fn with_hms() { assert_eq!( - date!(1970 - 01 - 01).with_hms(0, 0, 0), + date!(1970-01-01).with_hms(0, 0, 0), Ok(datetime!(1970-01-01 0:00)), ); - assert!(date!(1970 - 01 - 01).with_hms(24, 0, 0).is_err()); + assert!(date!(1970-01-01).with_hms(24, 0, 0).is_err()); } #[test] fn with_hms_milli() { assert_eq!( - date!(1970 - 01 - 01).with_hms_milli(0, 0, 0, 0), + date!(1970-01-01).with_hms_milli(0, 0, 0, 0), Ok(datetime!(1970-01-01 0:00)), ); - assert!(date!(1970 - 01 - 01).with_hms_milli(24, 0, 0, 0).is_err()); + assert!(date!(1970-01-01).with_hms_milli(24, 0, 0, 0).is_err()); } #[test] fn with_hms_micro() { assert_eq!( - date!(1970 - 01 - 01).with_hms_micro(0, 0, 0, 0), + date!(1970-01-01).with_hms_micro(0, 0, 0, 0), Ok(datetime!(1970-01-01 0:00)), ); - assert!(date!(1970 - 01 - 01).with_hms_micro(24, 0, 0, 0).is_err()); + assert!(date!(1970-01-01).with_hms_micro(24, 0, 0, 0).is_err()); } #[test] fn with_hms_nano() { assert_eq!( - date!(1970 - 01 - 01).with_hms_nano(0, 0, 0, 0), + date!(1970-01-01).with_hms_nano(0, 0, 0, 0), Ok(datetime!(1970-01-01 0:00)), ); - assert!(date!(1970 - 01 - 01).with_hms_nano(24, 0, 0, 0).is_err()); + assert!(date!(1970-01-01).with_hms_nano(24, 0, 0, 0).is_err()); } #[test] fn add() { - assert_eq!(date!(2019 - 01 - 01) + 5.days(), date!(2019 - 01 - 06)); - assert_eq!(date!(2019 - 12 - 31) + 1.days(), date!(2020 - 01 - 01)); + assert_eq!(date!(2019-01-01) + 5.days(), date!(2019-01-06)); + assert_eq!(date!(2019-12-31) + 1.days(), date!(2020-01-01)); } #[test] fn add_std() { - assert_eq!(date!(2019 - 01 - 01) + 5.std_days(), date!(2019 - 01 - 06)); - assert_eq!(date!(2019 - 12 - 31) + 1.std_days(), date!(2020 - 01 - 01)); + assert_eq!(date!(2019-01-01) + 5.std_days(), date!(2019-01-06)); + assert_eq!(date!(2019-12-31) + 1.std_days(), date!(2020-01-01)); } #[test] fn add_assign() { - let mut date = date!(2019 - 12 - 31); + let mut date = date!(2019-12-31); date += 1.days(); - assert_eq!(date, date!(2020 - 01 - 01)); + assert_eq!(date, date!(2020-01-01)); } #[test] fn add_assign_std() { - let mut date = date!(2019 - 12 - 31); + let mut date = date!(2019-12-31); date += 1.std_days(); - assert_eq!(date, date!(2020 - 01 - 01)); + assert_eq!(date, date!(2020-01-01)); } #[test] fn sub() { - assert_eq!(date!(2019 - 01 - 06) - 5.days(), date!(2019 - 01 - 01)); - assert_eq!(date!(2020 - 01 - 01) - 1.days(), date!(2019 - 12 - 31)); + assert_eq!(date!(2019-01-06) - 5.days(), date!(2019-01-01)); + assert_eq!(date!(2020-01-01) - 1.days(), date!(2019-12-31)); } #[test] fn sub_std() { - assert_eq!(date!(2019 - 01 - 06) - 5.std_days(), date!(2019 - 01 - 01)); - assert_eq!(date!(2020 - 01 - 01) - 1.std_days(), date!(2019 - 12 - 31)); + assert_eq!(date!(2019-01-06) - 5.std_days(), date!(2019-01-01)); + assert_eq!(date!(2020-01-01) - 1.std_days(), date!(2019-12-31)); } #[test] fn sub_assign() { - let mut date = date!(2020 - 01 - 01); + let mut date = date!(2020-01-01); date -= 1.days(); - assert_eq!(date, date!(2019 - 12 - 31)); + assert_eq!(date, date!(2019-12-31)); } #[test] fn sub_assign_std() { - let mut date = date!(2020 - 01 - 01); + let mut date = date!(2020-01-01); date -= 1.std_days(); - assert_eq!(date, date!(2019 - 12 - 31)); + assert_eq!(date, date!(2019-12-31)); } #[test] fn sub_self() { - assert_eq!(date!(2019 - 01 - 06) - date!(2019 - 01 - 01), 5.days()); - assert_eq!(date!(2020 - 01 - 01) - date!(2019 - 12 - 31), 1.days()); + assert_eq!(date!(2019-01-06) - date!(2019-01-01), 5.days()); + assert_eq!(date!(2020-01-01) - date!(2019-12-31), 1.days()); } #[test] fn partial_ord() { - let first = date!(2019 - 01 - 01); - let second = date!(2019 - 01 - 02); + let first = date!(2019-01-01); + let second = date!(2019-01-02); assert_eq!(first.partial_cmp(&first), Some(Ordering::Equal)); assert_eq!(first.partial_cmp(&second), Some(Ordering::Less)); @@ -798,8 +759,8 @@ fn partial_ord() { #[test] fn ord() { - let first = date!(2019 - 01 - 01); - let second = date!(2019 - 01 - 02); + let first = date!(2019-01-01); + let second = date!(2019-01-02); assert_eq!(first.cmp(&first), Ordering::Equal); assert_eq!(first.cmp(&second), Ordering::Less); @@ -808,7 +769,7 @@ fn ord() { #[test] fn regression_check() { - let (year, week, weekday) = (date!(0063 - 365)).to_iso_week_date(); + let (year, week, weekday) = (date!(0063-365)).to_iso_week_date(); assert_eq!(year, 64); assert_eq!(week, 1); assert_eq!(weekday, Weekday::Monday); @@ -827,12 +788,12 @@ fn checked_add_duration() { ); assert_eq!( - date!(2021 - 10 - 25).checked_add(Duration::new(86_399, 999_999_999)), - Some(date!(2021 - 10 - 25)) + date!(2021-10-25).checked_add(Duration::new(86_399, 999_999_999)), + Some(date!(2021-10-25)) ); assert_eq!( - date!(2021 - 10 - 25).checked_add(Duration::new(-86_399, -999_999_999)), - Some(date!(2021 - 10 - 25)) + date!(2021-10-25).checked_add(Duration::new(-86_399, -999_999_999)), + Some(date!(2021-10-25)) ); assert_eq!( @@ -849,12 +810,12 @@ fn checked_add_duration() { assert_eq!(Date::MIN.checked_add(-Duration::DAY), None); assert_eq!( - date!(2021 - 10 - 25).checked_add(Duration::DAY), - Some(date!(2021 - 10 - 26)) + date!(2021-10-25).checked_add(Duration::DAY), + Some(date!(2021-10-26)) ); assert_eq!( - date!(2021 - 10 - 25).checked_add(-Duration::DAY), - Some(date!(2021 - 10 - 24)) + date!(2021-10-25).checked_add(-Duration::DAY), + Some(date!(2021-10-24)) ); assert_eq!(Date::MAX.checked_add(Duration::DAY), None); @@ -881,12 +842,12 @@ fn checked_sub_duration() { ); assert_eq!( - date!(2021 - 10 - 25).checked_sub(Duration::new(86_399, 999_999_999)), - Some(date!(2021 - 10 - 25)) + date!(2021-10-25).checked_sub(Duration::new(86_399, 999_999_999)), + Some(date!(2021-10-25)) ); assert_eq!( - date!(2021 - 10 - 25).checked_sub(Duration::new(-86_399, -999_999_999)), - Some(date!(2021 - 10 - 25)) + date!(2021-10-25).checked_sub(Duration::new(-86_399, -999_999_999)), + Some(date!(2021-10-25)) ); assert_eq!( @@ -903,12 +864,12 @@ fn checked_sub_duration() { assert_eq!(Date::MIN.checked_sub(-Duration::DAY), Date::MIN.next_day()); assert_eq!( - date!(2021 - 10 - 25).checked_sub(Duration::DAY), - Some(date!(2021 - 10 - 24)) + date!(2021-10-25).checked_sub(Duration::DAY), + Some(date!(2021-10-24)) ); assert_eq!( - date!(2021 - 10 - 25).checked_sub(-Duration::DAY), - Some(date!(2021 - 10 - 26)) + date!(2021-10-25).checked_sub(-Duration::DAY), + Some(date!(2021-10-26)) ); assert_eq!( @@ -925,12 +886,12 @@ fn checked_sub_duration() { #[test] fn saturating_add_duration() { assert_eq!( - date!(2021 - 11 - 05).saturating_add(2.days()), - date!(2021 - 11 - 07) + date!(2021-11-05).saturating_add(2.days()), + date!(2021-11-07) ); assert_eq!( - date!(2021 - 11 - 05).saturating_add((-2).days()), - date!(2021 - 11 - 03) + date!(2021-11-05).saturating_add((-2).days()), + date!(2021-11-03) ); // Adding with underflow @@ -947,12 +908,12 @@ fn saturating_add_duration() { #[test] fn saturating_sub_duration() { assert_eq!( - date!(2021 - 11 - 05).saturating_sub(2.days()), - date!(2021 - 11 - 03) + date!(2021-11-05).saturating_sub(2.days()), + date!(2021-11-03) ); assert_eq!( - date!(2021 - 11 - 05).saturating_sub((-2).days()), - date!(2021 - 11 - 07) + date!(2021-11-05).saturating_sub((-2).days()), + date!(2021-11-07) ); // Subtracting with underflow @@ -968,186 +929,153 @@ fn saturating_sub_duration() { #[test] fn replace_year() { - assert_eq!( - date!(2022 - 02 - 18).replace_year(2019), - Ok(date!(2019 - 02 - 18)) - ); - assert!(date!(2022 - 02 - 18).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year - assert!(date!(2022 - 02 - 18).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year + assert_eq!(date!(2022-02-18).replace_year(2019), Ok(date!(2019-02-18))); + assert!(date!(2022-02-18).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year + assert!(date!(2022-02-18).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year // Common to leap year, before leap day. - assert_eq!( - date!(2022 - 01 - 01).replace_year(2024), - Ok(date!(2024 - 01 - 01)) - ); + assert_eq!(date!(2022-01-01).replace_year(2024), Ok(date!(2024-01-01))); // Common to leap year, after leap day. - assert_eq!( - date!(2022 - 12 - 01).replace_year(2024), - Ok(date!(2024 - 12 - 01)) - ); + assert_eq!(date!(2022-12-01).replace_year(2024), Ok(date!(2024-12-01))); // Leap to common year, before leap day. - assert_eq!( - date!(2024 - 01 - 01).replace_year(2022), - Ok(date!(2022 - 01 - 01)) - ); + assert_eq!(date!(2024-01-01).replace_year(2022), Ok(date!(2022-01-01))); // Leap to common year, after leap day. - assert_eq!( - date!(2024 - 12 - 01).replace_year(2022), - Ok(date!(2022 - 12 - 01)) - ); + assert_eq!(date!(2024-12-01).replace_year(2022), Ok(date!(2022-12-01))); // Leap to common year, leap day. - assert!(date!(2024 - 02 - 29).replace_year(2022).is_err()); + assert!(date!(2024-02-29).replace_year(2022).is_err()); // Common to common year. - assert_eq!( - date!(2022 - 12 - 01).replace_year(2023), - Ok(date!(2023 - 12 - 01)) - ); + assert_eq!(date!(2022-12-01).replace_year(2023), Ok(date!(2023-12-01))); // Leap to leap year. - assert_eq!( - date!(2024 - 12 - 01).replace_year(2028), - Ok(date!(2028 - 12 - 01)) - ); + assert_eq!(date!(2024-12-01).replace_year(2028), Ok(date!(2028-12-01))); } #[test] fn replace_month() { assert_eq!( - date!(2022 - 02 - 18).replace_month(Month::January), - Ok(date!(2022 - 01 - 18)) + date!(2022-02-18).replace_month(Month::January), + Ok(date!(2022-01-18)) ); - assert!( - date!(2022 - 01 - 30) - .replace_month(Month::February) - .is_err() - ); // 30 isn't a valid day in February + // 30 isn't a valid day in February + assert!(date!(2022-01-30).replace_month(Month::February).is_err()); } #[test] fn replace_day() { - assert_eq!( - date!(2022 - 02 - 18).replace_day(1), - Ok(date!(2022 - 02 - 01)) - ); - assert!(date!(2022 - 02 - 18).replace_day(0).is_err()); // 0 isn't a valid day - assert!(date!(2022 - 02 - 18).replace_day(30).is_err()); // 30 isn't a valid day in February + assert_eq!(date!(2022-02-18).replace_day(1), Ok(date!(2022-02-01))); + assert!(date!(2022-02-18).replace_day(0).is_err()); // 0 isn't a valid day + assert!(date!(2022-02-18).replace_day(30).is_err()); // 30 isn't a valid day in February } #[test] fn replace_ordinal() { - assert_eq!( - date!(2022 - 02 - 18).replace_ordinal(1), - Ok(date!(2022 - 001)) - ); - assert_eq!( - date!(2024 - 02 - 29).replace_ordinal(366), - Ok(date!(2024 - 366)) - ); - assert!(date!(2022 - 049).replace_ordinal(0).is_err()); // 0 isn't a valid day - assert!(date!(2022 - 049).replace_ordinal(366).is_err()); // 2022 isn't a leap year - assert!(date!(2022 - 049).replace_ordinal(367).is_err()); // 367 isn't a valid day + assert_eq!(date!(2022-02-18).replace_ordinal(1), Ok(date!(2022-001))); + assert_eq!(date!(2024-02-29).replace_ordinal(366), Ok(date!(2024-366))); + assert!(date!(2022-049).replace_ordinal(0).is_err()); // 0 isn't a valid day + assert!(date!(2022-049).replace_ordinal(366).is_err()); // 2022 isn't a leap year + assert!(date!(2022-049).replace_ordinal(367).is_err()); // 367 isn't a valid day } #[test] fn next_occurrence_test() { assert_eq!( - date!(2023 - 06 - 25).next_occurrence(Weekday::Monday), - date!(2023 - 06 - 26) + date!(2023-06-25).next_occurrence(Weekday::Monday), + date!(2023-06-26) ); assert_eq!( - date!(2023 - 06 - 26).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-06-26).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 06 - 27).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-06-27).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 06 - 28).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-06-28).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 06 - 29).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-06-29).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 06 - 30).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-06-30).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 07 - 01).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-07-01).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 07 - 02).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 03) + date!(2023-07-02).next_occurrence(Weekday::Monday), + date!(2023-07-03) ); assert_eq!( - date!(2023 - 07 - 03).next_occurrence(Weekday::Monday), - date!(2023 - 07 - 10) + date!(2023-07-03).next_occurrence(Weekday::Monday), + date!(2023-07-10) ); } #[test] fn prev_occurrence_test() { assert_eq!( - date!(2023 - 07 - 07).prev_occurrence(Weekday::Thursday), - date!(2023 - 07 - 06) + date!(2023-07-07).prev_occurrence(Weekday::Thursday), + date!(2023-07-06) ); assert_eq!( - date!(2023 - 07 - 06).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-06).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 07 - 05).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-05).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 07 - 04).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-04).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 07 - 03).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-03).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 07 - 02).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-02).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 07 - 01).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-07-01).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 06 - 30).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 29) + date!(2023-06-30).prev_occurrence(Weekday::Thursday), + date!(2023-06-29) ); assert_eq!( - date!(2023 - 06 - 29).prev_occurrence(Weekday::Thursday), - date!(2023 - 06 - 22) + date!(2023-06-29).prev_occurrence(Weekday::Thursday), + date!(2023-06-22) ); } #[test] fn nth_next_occurrence_test() { assert_eq!( - date!(2023 - 06 - 25).nth_next_occurrence(Weekday::Monday, 5), - date!(2023 - 07 - 24) + date!(2023-06-25).nth_next_occurrence(Weekday::Monday, 5), + date!(2023-07-24) ); assert_eq!( - date!(2023 - 06 - 26).nth_next_occurrence(Weekday::Monday, 5), - date!(2023 - 07 - 31) + date!(2023-06-26).nth_next_occurrence(Weekday::Monday, 5), + date!(2023-07-31) ); } #[test] fn nth_prev_occurrence_test() { assert_eq!( - date!(2023 - 06 - 27).nth_prev_occurrence(Weekday::Monday, 3), - date!(2023 - 06 - 12) + date!(2023-06-27).nth_prev_occurrence(Weekday::Monday, 3), + date!(2023-06-12) ); assert_eq!( - date!(2023 - 06 - 26).nth_prev_occurrence(Weekday::Monday, 3), - date!(2023 - 06 - 05) + date!(2023-06-26).nth_prev_occurrence(Weekday::Monday, 3), + date!(2023-06-05) ); } @@ -1172,13 +1100,13 @@ fn nth_next_occurrence_overflow_test() { #[test] #[should_panic] fn nth_next_occurence_zeroth_occurence_test() { - date!(2023 - 06 - 25).nth_next_occurrence(Weekday::Monday, 0); + date!(2023-06-25).nth_next_occurrence(Weekday::Monday, 0); } #[test] #[should_panic] fn nth_prev_occurence_zeroth_occurence_test() { - date!(2023 - 06 - 27).nth_prev_occurrence(Weekday::Monday, 0); + date!(2023-06-27).nth_prev_occurrence(Weekday::Monday, 0); } #[test] diff --git a/tests/derives.rs b/tests/derives.rs index d2f638cc6f..2c76eaeeaf 100644 --- a/tests/derives.rs +++ b/tests/derives.rs @@ -31,7 +31,7 @@ fn invalid_format_description() -> error::InvalidFormatDescription { fn clone() { #[allow(deprecated)] let instant = Instant::now(); - assert_cloned_eq!(date!(2021 - 001)); + assert_cloned_eq!(date!(2021-001)); assert_cloned_eq!(time!(0:00)); assert_cloned_eq!(offset!(UTC)); assert_cloned_eq!(datetime!(2021-001 0:00)); @@ -91,7 +91,7 @@ fn clone() { #[test] fn hash() { let mut hasher = DefaultHasher::new(); - date!(2021 - 001).hash(&mut hasher); + date!(2021-001).hash(&mut hasher); time!(0:00).hash(&mut hasher); offset!(UTC).hash(&mut hasher); datetime!(2021-001 0:00).hash(&mut hasher); diff --git a/tests/formatting.rs b/tests/formatting.rs index 53c5a2e611..7fa94c557a 100644 --- a/tests/formatting.rs +++ b/tests/formatting.rs @@ -110,12 +110,10 @@ fn iso_8601() -> time::Result<()> { }; } - assert!( - std::panic::catch_unwind(|| { - let _unused = datetime!(2021-01-02 03:04:05 UTC).format(&Iso8601::PARSING); - }) - .is_err() - ); + assert!(std::panic::catch_unwind(|| { + let _unused = datetime!(2021-01-02 03:04:05 UTC).format(&Iso8601::PARSING); + }) + .is_err()); assert_eq!( datetime!(-123_456-01-02 03:04:05 UTC).format( &Iso8601::< @@ -287,20 +285,16 @@ fn format_time() -> time::Result<()> { time!(13:02:03.456_789_012).format(format_description)?, output ); - assert!( - time!(13:02:03.456_789_012) - .format_into(&mut io::sink(), format_description) - .is_ok() - ); + assert!(time!(13:02:03.456_789_012) + .format_into(&mut io::sink(), format_description) + .is_ok()); assert_eq!( time!(13:02:03.456_789_012).format(&OwnedFormatItem::from(format_description))?, output ); - assert!( - time!(13:02:03.456_789_012) - .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) - .is_ok() - ); + assert!(time!(13:02:03.456_789_012) + .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) + .is_ok()); } assert_eq!( @@ -397,21 +391,17 @@ fn format_date() -> time::Result<()> { ]; for &(format_description, output) in &format_output { - assert_eq!(date!(2019 - 12 - 31).format(format_description)?, output); - assert!( - date!(2019 - 12 - 31) - .format_into(&mut io::sink(), format_description) - .is_ok() - ); + assert_eq!(date!(2019-12-31).format(format_description)?, output); + assert!(date!(2019-12-31) + .format_into(&mut io::sink(), format_description) + .is_ok()); assert_eq!( - date!(2019 - 12 - 31).format(&OwnedFormatItem::from(format_description))?, + date!(2019-12-31).format(&OwnedFormatItem::from(format_description))?, output ); - assert!( - date!(2019 - 12 - 31) - .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) - .is_ok() - ); + assert!(date!(2019-12-31) + .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) + .is_ok()); } Ok(()) @@ -419,8 +409,8 @@ fn format_date() -> time::Result<()> { #[test] fn display_date() { - assert_eq!(date!(2019 - 01 - 01).to_string(), "2019-01-01"); - assert_eq!(date!(2019 - 12 - 31).to_string(), "2019-12-31"); + assert_eq!(date!(2019-01-01).to_string(), "2019-01-01"); + assert_eq!(date!(2019-12-31).to_string(), "2019-12-31"); assert_eq!(date!(-4713 - 11 - 24).to_string(), "-4713-11-24"); assert_eq!(date!(-0001 - 01 - 01).to_string(), "-0001-01-01"); @@ -459,20 +449,16 @@ fn format_offset() -> time::Result<()> { for &(value, format_description, output) in &value_format_output { assert_eq!(value.format(format_description)?, output); - assert!( - value - .format_into(&mut io::sink(), format_description) - .is_ok() - ); + assert!(value + .format_into(&mut io::sink(), format_description) + .is_ok()); assert_eq!( value.format(&OwnedFormatItem::from(format_description))?, output ); - assert!( - value - .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) - .is_ok() - ); + assert!(value + .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) + .is_ok()); } Ok(()) @@ -502,20 +488,16 @@ fn format_pdt() -> time::Result<()> { datetime!(1970-01-01 0:00).format(format_description)?, "1970-01-01 00:00:00.0" ); - assert!( - datetime!(1970-01-01 0:00) - .format_into(&mut io::sink(), format_description) - .is_ok() - ); + assert!(datetime!(1970-01-01 0:00) + .format_into(&mut io::sink(), format_description) + .is_ok()); assert_eq!( datetime!(1970-01-01 0:00).format(&OwnedFormatItem::from(format_description))?, "1970-01-01 00:00:00.0" ); - assert!( - datetime!(1970-01-01 0:00) - .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) - .is_ok() - ); + assert!(datetime!(1970-01-01 0:00) + .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) + .is_ok()); Ok(()) } @@ -543,20 +525,16 @@ fn format_odt() -> time::Result<()> { datetime!(1970-01-01 0:00 UTC).format(&format_description)?, "1970-01-01 00:00:00.0 +00:00:00" ); - assert!( - datetime!(1970-01-01 0:00 UTC) - .format_into(&mut io::sink(), &format_description) - .is_ok() - ); + assert!(datetime!(1970-01-01 0:00 UTC) + .format_into(&mut io::sink(), &format_description) + .is_ok()); assert_eq!( datetime!(1970-01-01 0:00 UTC).format(&OwnedFormatItem::from(&format_description))?, "1970-01-01 00:00:00.0 +00:00:00" ); - assert!( - datetime!(1970-01-01 0:00 UTC) - .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) - .is_ok() - ); + assert!(datetime!(1970-01-01 0:00 UTC) + .format_into(&mut io::sink(), &OwnedFormatItem::from(format_description)) + .is_ok()); Ok(()) } @@ -579,16 +557,16 @@ fn insufficient_type_information() { }; assert_insufficient_type_information(Time::MIDNIGHT.format(fd!("[year]"))); assert_insufficient_type_information(Time::MIDNIGHT.format(&Rfc3339)); - assert_insufficient_type_information(date!(2021 - 001).format(&Rfc3339)); - assert_insufficient_type_information(datetime!(2021 - 001 0:00).format(&Rfc3339)); + assert_insufficient_type_information(date!(2021-001).format(&Rfc3339)); + assert_insufficient_type_information(datetime!(2021-001 0:00).format(&Rfc3339)); assert_insufficient_type_information(Time::MIDNIGHT.format(&Rfc2822)); - assert_insufficient_type_information(date!(2021 - 001).format(&Rfc2822)); - assert_insufficient_type_information(datetime!(2021 - 001 0:00).format(&Rfc2822)); + assert_insufficient_type_information(date!(2021-001).format(&Rfc2822)); + assert_insufficient_type_information(datetime!(2021-001 0:00).format(&Rfc2822)); assert_insufficient_type_information(Time::MIDNIGHT.format(&BorrowedFormatItem::First(&[ BorrowedFormatItem::Compound(fd!("[year]")), ]))); assert_insufficient_type_information(Time::MIDNIGHT.format(&Iso8601::DEFAULT)); - assert_insufficient_type_information(date!(2021 - 001).format(&Iso8601::DEFAULT)); + assert_insufficient_type_information(date!(2021-001).format(&Iso8601::DEFAULT)); assert_insufficient_type_information(datetime!(2021-001 0:00).format(&Iso8601::DEFAULT)); } @@ -711,7 +689,7 @@ fn failed_write() -> time::Result<()> { assert_err!(offset!(+1), fd!("[offset_hour sign:mandatory]")); assert_err!(offset!(-1), fd!("[offset_hour]")); assert_err!(date!(-1 - 001), fd!("[year]")); - assert_err!(date!(2021 - 001), fd!("[year sign:mandatory]")); + assert_err!(date!(2021-001), fd!("[year sign:mandatory]")); assert_err!(date!(+999_999 - 001), fd!("[year]")); assert_err!(date!(+99_999 - 001), fd!("[year]")); diff --git a/tests/macros.rs b/tests/macros.rs index 855fad85c7..3ac54b69fd 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -354,7 +354,7 @@ fn format_description_coverage() { #[rstest] fn date_coverage() { - assert_eq!(Ok(date!(2000 - 001)), Date::from_ordinal_date(2000, 1)); + assert_eq!(Ok(date!(2000-001)), Date::from_ordinal_date(2000, 1)); assert_eq!(Ok(date!(2019-W 01-1)), Date::from_ordinal_date(2018, 365)); assert_eq!(Ok(date!(2021-W 52-6)), Date::from_ordinal_date(2022, 1)); assert_eq!(Ok(date!(2021-W 34-5)), Date::from_ordinal_date(2021, 239)); diff --git a/tests/offset_date_time.rs b/tests/offset_date_time.rs index 8024abdc06..c0c652fca7 100644 --- a/tests/offset_date_time.rs +++ b/tests/offset_date_time.rs @@ -7,7 +7,7 @@ use time::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Weekday}; #[test] fn new_utc() { - let dt = OffsetDateTime::new_utc(date!(2023 - 12 - 18), time!(10:13:44.250 AM)); + let dt = OffsetDateTime::new_utc(date!(2023-12-18), time!(10:13:44.250 AM)); assert_eq!(dt.year(), 2023); assert_eq!(dt.millisecond(), 250); assert_eq!(dt.offset(), offset!(UTC)); @@ -15,8 +15,7 @@ fn new_utc() { #[test] fn new_in_offset() { - let dt = - OffsetDateTime::new_in_offset(date!(2023 - 12 - 18), time!(10:13:44.250 AM), offset!(-4)); + let dt = OffsetDateTime::new_in_offset(date!(2023-12-18), time!(10:13:44.250 AM), offset!(-4)); assert_eq!(dt.year(), 2023); assert_eq!(dt.millisecond(), 250); assert_eq!(dt.offset().whole_hours(), -4); @@ -159,10 +158,10 @@ fn unix_timestamp_nanos() { #[test] fn date() { - assert_eq!(datetime!(2019-01-01 0:00 UTC).date(), date!(2019 - 01 - 01)); + assert_eq!(datetime!(2019-01-01 0:00 UTC).date(), date!(2019-01-01)); assert_eq!( datetime!(2019-01-01 0:00 UTC).to_offset(offset!(-1)).date(), - date!(2018 - 12 - 31), + date!(2018-12-31), ); } @@ -405,11 +404,11 @@ fn replace_time() { #[test] fn replace_date() { assert_eq!( - datetime!(2020-01-01 12:00 UTC).replace_date(date!(2020 - 01 - 30)), + datetime!(2020-01-01 12:00 UTC).replace_date(date!(2020-01-30)), datetime!(2020-01-30 12:00 UTC) ); assert_eq!( - datetime!(2020-01-01 0:00 +1).replace_date(date!(2020 - 01 - 30)), + datetime!(2020-01-01 0:00 +1).replace_date(date!(2020-01-30)), datetime!(2020-01-30 0:00 +1) ); } @@ -437,13 +436,13 @@ fn replace_offset() { #[test] fn replace_year() { assert_eq!( - datetime!(2022 - 02 - 18 12:00 +01).replace_year(2019), - Ok(datetime!(2019 - 02 - 18 12:00 +01)) + datetime!(2022-02-18 12:00 +01).replace_year(2019), + Ok(datetime!(2019-02-18 12:00 +01)) ); - assert!(datetime!(2022 - 02 - 18 12:00 +01) + assert!(datetime!(2022-02-18 12:00 +01) .replace_year(-1_000_000_000) .is_err()); // -1_000_000_000 isn't a valid year - assert!(datetime!(2022 - 02 - 18 12:00 +01) + assert!(datetime!(2022-02-18 12:00 +01) .replace_year(1_000_000_000) .is_err()); // 1_000_000_000 isn't a valid year } @@ -451,10 +450,10 @@ fn replace_year() { #[test] fn replace_month() { assert_eq!( - datetime!(2022 - 02 - 18 12:00 +01).replace_month(Month::January), - Ok(datetime!(2022 - 01 - 18 12:00 +01)) + datetime!(2022-02-18 12:00 +01).replace_month(Month::January), + Ok(datetime!(2022-01-18 12:00 +01)) ); - assert!(datetime!(2022 - 01 - 30 12:00 +01) + assert!(datetime!(2022-01-30 12:00 +01) .replace_month(Month::February) .is_err()); // 30 isn't a valid day in February } @@ -462,40 +461,37 @@ fn replace_month() { #[test] fn replace_day() { assert_eq!( - datetime!(2022 - 02 - 18 12:00 +01).replace_day(1), - Ok(datetime!(2022 - 02 - 01 12:00 +01)) + datetime!(2022-02-18 12:00 +01).replace_day(1), + Ok(datetime!(2022-02-01 12:00 +01)) ); - assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_day(0).is_err()); // 00 isn't a valid day - assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_day(30).is_err()); // 30 isn't a valid day - // in February + // 00 isn't a valid day + assert!(datetime!(2022-02-18 12:00 +01).replace_day(0).is_err()); + // 30 isn't a valid day in February + assert!(datetime!(2022-02-18 12:00 +01).replace_day(30).is_err()); } #[test] fn replace_ordinal() { assert_eq!( - datetime!(2022 - 02 - 18 12:00 +01).replace_ordinal(1), - Ok(datetime!(2022 - 001 12:00 +01)) + datetime!(2022-02-18 12:00 +01).replace_ordinal(1), + Ok(datetime!(2022-001 12:00 +01)) ); assert_eq!( - datetime!(2024 - 02 - 29 12:00 +01).replace_ordinal(366), - Ok(datetime!(2024 - 366 12:00 +01)) + datetime!(2024-02-29 12:00 +01).replace_ordinal(366), + Ok(datetime!(2024-366 12:00 +01)) ); - assert!(datetime!(2022 - 049 12:00 +01).replace_ordinal(0).is_err()); // 0 isn't a valid day - assert!(datetime!(2022 - 049 12:00 +01) - .replace_ordinal(366) - .is_err()); // 2022 isn't a leap year - assert!(datetime!(2022 - 049 12:00 +01) - .replace_ordinal(367) - .is_err()); // 367 isn't a valid day + assert!(datetime!(2022-049 12:00 +01).replace_ordinal(0).is_err()); // 0 isn't a valid day + assert!(datetime!(2022-049 12:00 +01).replace_ordinal(366).is_err()); // 2022 isn't a leap year + assert!(datetime!(2022-049 12:00 +01).replace_ordinal(367).is_err()); // 367 isn't a valid day } #[test] fn replace_hour() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_hour(7), - Ok(datetime!(2022 - 02 - 18 07:02:03.004_005_006 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_hour(7), + Ok(datetime!(2022-02-18 07:02:03.004_005_006 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_hour(24) .is_err()); // 24 isn't a valid hour } @@ -503,10 +499,10 @@ fn replace_hour() { #[test] fn replace_minute() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_minute(7), - Ok(datetime!(2022 - 02 - 18 01:07:03.004_005_006 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_minute(7), + Ok(datetime!(2022-02-18 01:07:03.004_005_006 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_minute(60) .is_err()); // 60 isn't a valid minute } @@ -514,10 +510,10 @@ fn replace_minute() { #[test] fn replace_second() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_second(7), - Ok(datetime!(2022 - 02 - 18 01:02:07.004_005_006 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_second(7), + Ok(datetime!(2022-02-18 01:02:07.004_005_006 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_second(60) .is_err()); // 60 isn't a valid second } @@ -525,10 +521,10 @@ fn replace_second() { #[test] fn replace_millisecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_millisecond(7), - Ok(datetime!(2022 - 02 - 18 01:02:03.007 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_millisecond(7), + Ok(datetime!(2022-02-18 01:02:03.007 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_millisecond(1_000) .is_err()); // 1_000 isn't a valid millisecond } @@ -536,10 +532,10 @@ fn replace_millisecond() { #[test] fn replace_microsecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_microsecond(7_008), - Ok(datetime!(2022 - 02 - 18 01:02:03.007_008 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_microsecond(7_008), + Ok(datetime!(2022-02-18 01:02:03.007_008 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_microsecond(1_000_000) .is_err()); // 1_000_000 isn't a valid microsecond } @@ -547,10 +543,10 @@ fn replace_microsecond() { #[test] fn replace_nanosecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_nanosecond(7_008_009), - Ok(datetime!(2022 - 02 - 18 01:02:03.007_008_009 +01)) + datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_nanosecond(7_008_009), + Ok(datetime!(2022-02-18 01:02:03.007_008_009 +01)) ); - assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01) + assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01) .replace_nanosecond(1_000_000_000) .is_err()); // 1_000_000_000 isn't a valid nanosecond } @@ -1057,36 +1053,36 @@ fn to_std() { fn checked_add_duration() { // Successful addition assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add(5.nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.450_000_005 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add(5.nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.450_000_005 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add(4.seconds()), - Some(datetime!(2021 - 10 - 25 14:01:57.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add(4.seconds()), + Some(datetime!(2021-10-25 14:01:57.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add(2.days()), - Some(datetime!(2021 - 10 - 27 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add(2.days()), + Some(datetime!(2021-10-27 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add(1.weeks()), - Some(datetime!(2021 - 11 - 01 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add(1.weeks()), + Some(datetime!(2021-11-01 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add((-5).nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.449_999_995 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add((-5).nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.449_999_995 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add((-4).seconds()), - Some(datetime!(2021 - 10 - 25 14:01:49.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add((-4).seconds()), + Some(datetime!(2021-10-25 14:01:49.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add((-2).days()), - Some(datetime!(2021 - 10 - 23 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add((-2).days()), + Some(datetime!(2021-10-23 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_add((-1).weeks()), - Some(datetime!(2021 - 10 - 18 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_add((-1).weeks()), + Some(datetime!(2021-10-18 14:01:53.45 UTC)) ); // Addition with underflow @@ -1132,36 +1128,36 @@ fn checked_add_duration() { fn checked_sub_duration() { // Successful subtraction assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub((-5).nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.450_000_005 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub((-5).nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.450_000_005 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub((-4).seconds()), - Some(datetime!(2021 - 10 - 25 14:01:57.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub((-4).seconds()), + Some(datetime!(2021-10-25 14:01:57.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub((-2).days()), - Some(datetime!(2021 - 10 - 27 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub((-2).days()), + Some(datetime!(2021-10-27 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub((-1).weeks()), - Some(datetime!(2021 - 11 - 01 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub((-1).weeks()), + Some(datetime!(2021-11-01 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub(5.nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.449_999_995 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub(5.nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.449_999_995 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub(4.seconds()), - Some(datetime!(2021 - 10 - 25 14:01:49.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub(4.seconds()), + Some(datetime!(2021-10-25 14:01:49.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub(2.days()), - Some(datetime!(2021 - 10 - 23 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub(2.days()), + Some(datetime!(2021-10-23 14:01:53.45 UTC)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45 UTC).checked_sub(1.weeks()), - Some(datetime!(2021 - 10 - 18 14:01:53.45 UTC)) + datetime!(2021-10-25 14:01:53.45 UTC).checked_sub(1.weeks()), + Some(datetime!(2021-10-18 14:01:53.45 UTC)) ); // Subtraction with underflow @@ -1206,12 +1202,12 @@ fn checked_sub_duration() { #[test] fn saturating_add_duration() { assert_eq!( - datetime!(2021 - 11 - 12 17:47 +10).saturating_add(2.days()), - datetime!(2021 - 11 - 14 17:47 +10) + datetime!(2021-11-12 17:47 +10).saturating_add(2.days()), + datetime!(2021-11-14 17:47 +10) ); assert_eq!( - datetime!(2021 - 11 - 12 17:47 +10).saturating_add((-2).days()), - datetime!(2021 - 11 - 10 17:47 +10) + datetime!(2021-11-12 17:47 +10).saturating_add((-2).days()), + datetime!(2021-11-10 17:47 +10) ); // Adding with underflow @@ -1240,12 +1236,12 @@ fn saturating_add_duration() { #[test] fn saturating_sub_duration() { assert_eq!( - datetime!(2021 - 11 - 12 17:47 +10).saturating_sub(2.days()), - datetime!(2021 - 11 - 10 17:47 +10) + datetime!(2021-11-12 17:47 +10).saturating_sub(2.days()), + datetime!(2021-11-10 17:47 +10) ); assert_eq!( - datetime!(2021 - 11 - 12 17:47 +10).saturating_sub((-2).days()), - datetime!(2021 - 11 - 14 17:47 +10) + datetime!(2021-11-12 17:47 +10).saturating_sub((-2).days()), + datetime!(2021-11-14 17:47 +10) ); // Subtracting with underflow diff --git a/tests/parsing.rs b/tests/parsing.rs index 749ea95fb5..d3306ed667 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -74,28 +74,28 @@ fn rfc_2822() -> time::Result<()> { assert_eq!( Date::parse("Sat, 02 Jan 2021 03:04:05 GMT", &Rfc2822)?, - date!(2021 - 01 - 02) + date!(2021-01-02) ); assert_eq!( Date::parse("Sat, 02 Jan 2021 03:04:05 +0607", &Rfc2822)?, - date!(2021 - 01 - 02) + date!(2021-01-02) ); assert_eq!( Date::parse("Sat, 02 Jan 2021 03:04:05 -0607", &Rfc2822)?, - date!(2021 - 01 - 02) + date!(2021-01-02) ); assert_eq!( Date::parse("Sat, 02 Jan 21 03:04:05 -0607", &Rfc2822)?, - date!(2021 - 01 - 02) + date!(2021-01-02) ); assert_eq!( Date::parse("Sat, 02 Jan 71 03:04:05 -0607", &Rfc2822)?, - date!(1971 - 01 - 02) + date!(1971-01-02) ); assert_eq!( OffsetDateTime::parse("Sat,(\\\u{a})02 Jan 2021 03:04:05 GMT", &Rfc2822)?, - datetime!(2021 - 01 - 02 03:04:05 UTC), + datetime!(2021-01-02 03:04:05 UTC), ); #[rustfmt::skip] assert_eq!( @@ -122,7 +122,7 @@ fn issue_661() -> time::Result<()> { ); assert_eq!( Date::parse("02 Jan 2021 03:04:05 +0607", &Rfc2822)?, - date!(2021 - 01 - 02) + date!(2021-01-02) ); Ok(()) @@ -295,15 +295,15 @@ fn rfc_3339() -> time::Result<()> { assert_eq!( Date::parse("2021-01-02T03:04:05Z", &Rfc3339)?, - date!(2021 - 01 - 02), + date!(2021-01-02), ); assert_eq!( Date::parse("2021-01-02T03:04:05.123+01:02", &Rfc3339)?, - date!(2021 - 01 - 02), + date!(2021-01-02), ); assert_eq!( Date::parse("2021-01-02T03:04:05.123-01:02", &Rfc3339)?, - date!(2021 - 01 - 02), + date!(2021-01-02), ); assert_eq!( @@ -810,57 +810,53 @@ fn parse_date() -> time::Result<()> { ( fd::parse("[year]-[month]-[day]")?, "2021-01-02", - date!(2021 - 01 - 02), - ), - ( - fd::parse("[year]-[ordinal]")?, - "2021-002", - date!(2021 - 002), + date!(2021-01-02), ), + (fd::parse("[year]-[ordinal]")?, "2021-002", date!(2021-002)), ( fd::parse("[year base:iso_week]-W[week_number]-[weekday repr:monday]")?, "2020-W53-6", - date!(2021 - 01 - 02), + date!(2021-01-02), ), ( fd::parse("[year]-W[week_number repr:monday]-[weekday repr:monday]")?, "2021-W00-6", - date!(2021 - 01 - 02), + date!(2021-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2021-W00-6", - date!(2021 - 01 - 02), + date!(2021-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2023-W01-1", - date!(2023 - 01 - 02), + date!(2023-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2022-W00-7", - date!(2022 - 01 - 02), + date!(2022-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2026-W00-5", - date!(2026 - 01 - 02), + date!(2026-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2025-W00-4", - date!(2025 - 01 - 02), + date!(2025-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2019-W00-3", - date!(2019 - 01 - 02), + date!(2019-01-02), ), ( fd::parse("[year]-W[week_number repr:sunday]-[weekday repr:sunday]")?, "2018-W01-2", - date!(2018 - 01 - 02), + date!(2018-01-02), ), ( fd::parse( @@ -868,7 +864,7 @@ fn parse_date() -> time::Result<()> { repr:sunday]", )?, " 201-W01-2", - date!(201 - 01 - 06), + date!(201-01-06), ), ]; diff --git a/tests/primitive_date_time.rs b/tests/primitive_date_time.rs index 80b6da9e86..a9cf61d6e8 100644 --- a/tests/primitive_date_time.rs +++ b/tests/primitive_date_time.rs @@ -7,14 +7,14 @@ use time::{Duration, Month, PrimitiveDateTime, Weekday}; #[test] fn new() { assert_eq!( - PrimitiveDateTime::new(date!(2019 - 01 - 01), time!(0:00)), + PrimitiveDateTime::new(date!(2019-01-01), time!(0:00)), datetime!(2019-01-01 0:00), ); } #[test] fn date() { - assert_eq!(datetime!(2019-01-01 0:00).date(), date!(2019 - 01 - 01)); + assert_eq!(datetime!(2019-01-01 0:00).date(), date!(2019-01-01)); } #[test] @@ -242,7 +242,7 @@ fn replace_time() { #[test] fn replace_date() { assert_eq!( - datetime!(2020-01-01 12:00).replace_date(date!(2020 - 01 - 30)), + datetime!(2020-01-01 12:00).replace_date(date!(2020-01-30)), datetime!(2020-01-30 12:00) ); } @@ -250,135 +250,119 @@ fn replace_date() { #[test] fn replace_year() { assert_eq!( - datetime!(2022 - 02 - 18 12:00).replace_year(2019), - Ok(datetime!(2019 - 02 - 18 12:00)) + datetime!(2022-02-18 12:00).replace_year(2019), + Ok(datetime!(2019-02-18 12:00)) ); - assert!( - datetime!(2022 - 02 - 18 12:00) - .replace_year(-1_000_000_000) - .is_err() - ); // -1_000_000_000 isn't a valid year - assert!( - datetime!(2022 - 02 - 18 12:00) - .replace_year(1_000_000_000) - .is_err() - ); // 1_000_000_000 isn't a valid year + assert!(datetime!(2022-02-18 12:00) + .replace_year(-1_000_000_000) + .is_err()); // -1_000_000_000 isn't a valid year + assert!(datetime!(2022-02-18 12:00) + .replace_year(1_000_000_000) + .is_err()); // 1_000_000_000 isn't a valid year } #[test] fn replace_month() { assert_eq!( - datetime!(2022 - 02 - 18 12:00).replace_month(Month::January), - Ok(datetime!(2022 - 01 - 18 12:00)) + datetime!(2022-02-18 12:00).replace_month(Month::January), + Ok(datetime!(2022-01-18 12:00)) ); - assert!( - datetime!(2022 - 01 - 30 12:00) - .replace_month(Month::February) - .is_err() - ); // 30 isn't a valid day in February + assert!(datetime!(2022-01-30 12:00) + .replace_month(Month::February) + .is_err()); // 30 isn't a valid day in February } #[test] fn replace_day() { assert_eq!( - datetime!(2022 - 02 - 18 12:00).replace_day(1), - Ok(datetime!(2022 - 02 - 01 12:00)) + datetime!(2022-02-18 12:00).replace_day(1), + Ok(datetime!(2022-02-01 12:00)) ); - assert!(datetime!(2022 - 02 - 18 12:00).replace_day(0).is_err()); // 00 isn't a valid day - assert!(datetime!(2022 - 02 - 18 12:00).replace_day(30).is_err()); // 30 isn't a valid day in February + // 00 isn't a valid day + assert!(datetime!(2022-02-18 12:00).replace_day(0).is_err()); + // 30 isn't a valid day in February + assert!(datetime!(2022-02-18 12:00).replace_day(30).is_err()); } #[test] fn replace_ordinal() { assert_eq!( - datetime!(2022 - 02 - 18 12:00).replace_ordinal(1), - Ok(datetime!(2022 - 001 12:00)) + datetime!(2022-02-18 12:00).replace_ordinal(1), + Ok(datetime!(2022-001 12:00)) ); assert_eq!( - datetime!(2024 - 02 - 29 12:00).replace_ordinal(366), - Ok(datetime!(2024 - 366 12:00)) + datetime!(2024-02-29 12:00).replace_ordinal(366), + Ok(datetime!(2024-366 12:00)) ); - assert!(datetime!(2022 - 049 12:00).replace_ordinal(0).is_err()); // 0 isn't a valid day - assert!(datetime!(2022 - 049 12:00).replace_ordinal(366).is_err()); // 2022 isn't a leap year - assert!(datetime!(2022 - 049 12:00).replace_ordinal(367).is_err()); // 367 isn't a valid day + assert!(datetime!(2022-049 12:00).replace_ordinal(0).is_err()); // 0 isn't a valid day + assert!(datetime!(2022-049 12:00).replace_ordinal(366).is_err()); // 2022 isn't a leap year + assert!(datetime!(2022-049 12:00).replace_ordinal(367).is_err()); // 367 isn't a valid day } #[test] fn replace_hour() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_hour(7), - Ok(datetime!(2022 - 02 - 18 07:02:03.004_005_006)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_hour(7), + Ok(datetime!(2022-02-18 07:02:03.004_005_006)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_hour(24) - .is_err() - ); // 24 isn't a valid hour + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_hour(24) + .is_err()); // 24 isn't a valid hour } #[test] fn replace_minute() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_minute(7), - Ok(datetime!(2022 - 02 - 18 01:07:03.004_005_006)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_minute(7), + Ok(datetime!(2022-02-18 01:07:03.004_005_006)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_minute(60) - .is_err() - ); // 60 isn't a valid minute + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_minute(60) + .is_err()); // 60 isn't a valid minute } #[test] fn replace_second() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_second(7), - Ok(datetime!(2022 - 02 - 18 01:02:07.004_005_006)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_second(7), + Ok(datetime!(2022-02-18 01:02:07.004_005_006)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_second(60) - .is_err() - ); // 60 isn't a valid second + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_second(60) + .is_err()); // 60 isn't a valid second } #[test] fn replace_millisecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_millisecond(7), - Ok(datetime!(2022 - 02 - 18 01:02:03.007)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_millisecond(7), + Ok(datetime!(2022-02-18 01:02:03.007)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_millisecond(1_000) - .is_err() - ); // 1_000 isn't a valid millisecond + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_millisecond(1_000) + .is_err()); // 1_000 isn't a valid millisecond } #[test] fn replace_microsecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_microsecond(7_008), - Ok(datetime!(2022 - 02 - 18 01:02:03.007_008)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_microsecond(7_008), + Ok(datetime!(2022-02-18 01:02:03.007_008)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_microsecond(1_000_000) - .is_err() - ); // 1_000_000 isn't a valid microsecond + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_microsecond(1_000_000) + .is_err()); // 1_000_000 isn't a valid microsecond } #[test] fn replace_nanosecond() { assert_eq!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_nanosecond(7_008_009), - Ok(datetime!(2022 - 02 - 18 01:02:03.007_008_009)) + datetime!(2022-02-18 01:02:03.004_005_006).replace_nanosecond(7_008_009), + Ok(datetime!(2022-02-18 01:02:03.007_008_009)) ); - assert!( - datetime!(2022 - 02 - 18 01:02:03.004_005_006) - .replace_nanosecond(1_000_000_000) - .is_err() - ); // 1_000_000_000 isn't a valid nanosecond + assert!(datetime!(2022-02-18 01:02:03.004_005_006) + .replace_nanosecond(1_000_000_000) + .is_err()); // 1_000_000_000 isn't a valid nanosecond } #[test] @@ -618,36 +602,36 @@ fn ord() { fn checked_add_duration() { // Successful addition assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add(5.nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.450_000_005)) + datetime!(2021-10-25 14:01:53.45).checked_add(5.nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.450_000_005)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add(4.seconds()), - Some(datetime!(2021 - 10 - 25 14:01:57.45)) + datetime!(2021-10-25 14:01:53.45).checked_add(4.seconds()), + Some(datetime!(2021-10-25 14:01:57.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add(2.days()), - Some(datetime!(2021 - 10 - 27 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_add(2.days()), + Some(datetime!(2021-10-27 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add(1.weeks()), - Some(datetime!(2021 - 11 - 01 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_add(1.weeks()), + Some(datetime!(2021-11-01 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add((-5).nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.449_999_995)) + datetime!(2021-10-25 14:01:53.45).checked_add((-5).nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.449_999_995)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add((-4).seconds()), - Some(datetime!(2021 - 10 - 25 14:01:49.45)) + datetime!(2021-10-25 14:01:53.45).checked_add((-4).seconds()), + Some(datetime!(2021-10-25 14:01:49.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add((-2).days()), - Some(datetime!(2021 - 10 - 23 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_add((-2).days()), + Some(datetime!(2021-10-23 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_add((-1).weeks()), - Some(datetime!(2021 - 10 - 18 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_add((-1).weeks()), + Some(datetime!(2021-10-18 14:01:53.45)) ); // Addition with underflow @@ -683,36 +667,36 @@ fn checked_add_duration() { fn checked_sub_duration() { // Successful subtraction assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub((-5).nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.450_000_005)) + datetime!(2021-10-25 14:01:53.45).checked_sub((-5).nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.450_000_005)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub((-4).seconds()), - Some(datetime!(2021 - 10 - 25 14:01:57.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub((-4).seconds()), + Some(datetime!(2021-10-25 14:01:57.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub((-2).days()), - Some(datetime!(2021 - 10 - 27 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub((-2).days()), + Some(datetime!(2021-10-27 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub((-1).weeks()), - Some(datetime!(2021 - 11 - 01 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub((-1).weeks()), + Some(datetime!(2021-11-01 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub(5.nanoseconds()), - Some(datetime!(2021 - 10 - 25 14:01:53.449_999_995)) + datetime!(2021-10-25 14:01:53.45).checked_sub(5.nanoseconds()), + Some(datetime!(2021-10-25 14:01:53.449_999_995)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub(4.seconds()), - Some(datetime!(2021 - 10 - 25 14:01:49.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub(4.seconds()), + Some(datetime!(2021-10-25 14:01:49.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub(2.days()), - Some(datetime!(2021 - 10 - 23 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub(2.days()), + Some(datetime!(2021-10-23 14:01:53.45)) ); assert_eq!( - datetime!(2021 - 10 - 25 14:01:53.45).checked_sub(1.weeks()), - Some(datetime!(2021 - 10 - 18 14:01:53.45)) + datetime!(2021-10-25 14:01:53.45).checked_sub(1.weeks()), + Some(datetime!(2021-10-18 14:01:53.45)) ); // Subtraction with underflow @@ -747,12 +731,12 @@ fn checked_sub_duration() { #[test] fn saturating_add_duration() { assert_eq!( - datetime!(2021 - 11 - 12 17:47).saturating_add(2.days()), - datetime!(2021 - 11 - 14 17:47) + datetime!(2021-11-12 17:47).saturating_add(2.days()), + datetime!(2021-11-14 17:47) ); assert_eq!( - datetime!(2021 - 11 - 12 17:47).saturating_add((-2).days()), - datetime!(2021 - 11 - 10 17:47) + datetime!(2021-11-12 17:47).saturating_add((-2).days()), + datetime!(2021-11-10 17:47) ); // Adding with underflow @@ -781,12 +765,12 @@ fn saturating_add_duration() { #[test] fn saturating_sub_duration() { assert_eq!( - datetime!(2021 - 11 - 12 17:47).saturating_sub(2.days()), - datetime!(2021 - 11 - 10 17:47) + datetime!(2021-11-12 17:47).saturating_sub(2.days()), + datetime!(2021-11-10 17:47) ); assert_eq!( - datetime!(2021 - 11 - 12 17:47).saturating_sub((-2).days()), - datetime!(2021 - 11 - 14 17:47) + datetime!(2021-11-12 17:47).saturating_sub((-2).days()), + datetime!(2021-11-14 17:47) ); // Subtracting with underflow diff --git a/tests/serde/json.rs b/tests/serde/json.rs index 6c708d0203..5fb82747a1 100644 --- a/tests/serde/json.rs +++ b/tests/serde/json.rs @@ -135,7 +135,7 @@ fn duration_json() -> Result<(), Box> { #[test] fn date_json() -> Result<(), Box> { - let date = date!(2022 - 04 - 05); + let date = date!(2022-04-05); assert_eq!(serialize(date.compact())?, "[2022,95]"); assert_eq!(deserialize::("[2022,95]", Compact)?, date); diff --git a/tests/serde/macros.rs b/tests/serde/macros.rs index b58a513116..2bbea16984 100644 --- a/tests/serde/macros.rs +++ b/tests/serde/macros.rs @@ -69,7 +69,7 @@ fn custom_serialize() { let value = TestCustomFormat { offset_dt: datetime!(2000-01-01 00:00 -4:00), primitive_dt: Some(datetime!(2000-01-01 00:00)), - date: date!(2000 - 01 - 01), + date: date!(2000-01-01), time: None, offset: offset!(-4), time_alt: time!(12:34), diff --git a/time/src/date.rs b/time/src/date.rs index d7ef855072..92c28114bd 100644 --- a/time/src/date.rs +++ b/time/src/date.rs @@ -249,9 +249,9 @@ impl Date { /// # use time::Date; /// # use time_macros::date; /// assert_eq!(Date::from_julian_day(0), Ok(date!(-4713 - 11 - 24))); - /// assert_eq!(Date::from_julian_day(2_451_545), Ok(date!(2000 - 01 - 01))); - /// assert_eq!(Date::from_julian_day(2_458_485), Ok(date!(2019 - 01 - 01))); - /// assert_eq!(Date::from_julian_day(2_458_849), Ok(date!(2019 - 12 - 31))); + /// assert_eq!(Date::from_julian_day(2_451_545), Ok(date!(2000-01-01))); + /// assert_eq!(Date::from_julian_day(2_458_485), Ok(date!(2019-01-01))); + /// assert_eq!(Date::from_julian_day(2_458_849), Ok(date!(2019-12-31))); /// ``` #[doc(alias = "from_julian_date")] pub const fn from_julian_day(julian_day: i32) -> Result { @@ -306,9 +306,9 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).year(), 2019); - /// assert_eq!(date!(2019 - 12 - 31).year(), 2019); - /// assert_eq!(date!(2020 - 01 - 01).year(), 2020); + /// assert_eq!(date!(2019-01-01).year(), 2019); + /// assert_eq!(date!(2019-12-31).year(), 2019); + /// assert_eq!(date!(2020-01-01).year(), 2020); /// ``` pub const fn year(self) -> i32 { self.value.get() >> 9 @@ -319,8 +319,8 @@ impl Date { /// ```rust /// # use time::Month; /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).month(), Month::January); - /// assert_eq!(date!(2019 - 12 - 31).month(), Month::December); + /// assert_eq!(date!(2019-01-01).month(), Month::January); + /// assert_eq!(date!(2019-12-31).month(), Month::December); /// ``` pub const fn month(self) -> Month { self.month_day().0 @@ -332,8 +332,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).day(), 1); - /// assert_eq!(date!(2019 - 12 - 31).day(), 31); + /// assert_eq!(date!(2019-01-01).day(), 1); + /// assert_eq!(date!(2019-12-31).day(), 31); /// ``` pub const fn day(self) -> u8 { self.month_day().1 @@ -386,8 +386,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).ordinal(), 1); - /// assert_eq!(date!(2019 - 12 - 31).ordinal(), 365); + /// assert_eq!(date!(2019-01-01).ordinal(), 1); + /// assert_eq!(date!(2019-12-31).ordinal(), 365); /// ``` pub const fn ordinal(self) -> u16 { (self.value.get() & 0x1FF) as _ @@ -410,11 +410,11 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).iso_week(), 1); - /// assert_eq!(date!(2019 - 10 - 04).iso_week(), 40); - /// assert_eq!(date!(2020 - 01 - 01).iso_week(), 1); - /// assert_eq!(date!(2020 - 12 - 31).iso_week(), 53); - /// assert_eq!(date!(2021 - 01 - 01).iso_week(), 53); + /// assert_eq!(date!(2019-01-01).iso_week(), 1); + /// assert_eq!(date!(2019-10-04).iso_week(), 40); + /// assert_eq!(date!(2020-01-01).iso_week(), 1); + /// assert_eq!(date!(2020-12-31).iso_week(), 53); + /// assert_eq!(date!(2021-01-01).iso_week(), 53); /// ``` pub const fn iso_week(self) -> u8 { self.iso_year_week().1 @@ -426,10 +426,10 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).sunday_based_week(), 0); - /// assert_eq!(date!(2020 - 01 - 01).sunday_based_week(), 0); - /// assert_eq!(date!(2020 - 12 - 31).sunday_based_week(), 52); - /// assert_eq!(date!(2021 - 01 - 01).sunday_based_week(), 0); + /// assert_eq!(date!(2019-01-01).sunday_based_week(), 0); + /// assert_eq!(date!(2020-01-01).sunday_based_week(), 0); + /// assert_eq!(date!(2020-12-31).sunday_based_week(), 52); + /// assert_eq!(date!(2021-01-01).sunday_based_week(), 0); /// ``` pub const fn sunday_based_week(self) -> u8 { ((self.ordinal() as i16 - self.weekday().number_days_from_sunday() as i16 + 6) / 7) as _ @@ -441,10 +441,10 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).monday_based_week(), 0); - /// assert_eq!(date!(2020 - 01 - 01).monday_based_week(), 0); - /// assert_eq!(date!(2020 - 12 - 31).monday_based_week(), 52); - /// assert_eq!(date!(2021 - 01 - 01).monday_based_week(), 0); + /// assert_eq!(date!(2019-01-01).monday_based_week(), 0); + /// assert_eq!(date!(2020-01-01).monday_based_week(), 0); + /// assert_eq!(date!(2020-12-31).monday_based_week(), 52); + /// assert_eq!(date!(2021-01-01).monday_based_week(), 0); /// ``` pub const fn monday_based_week(self) -> u8 { ((self.ordinal() as i16 - self.weekday().number_days_from_monday() as i16 + 6) / 7) as _ @@ -456,7 +456,7 @@ impl Date { /// # use time::Month; /// # use time_macros::date; /// assert_eq!( - /// date!(2019 - 01 - 01).to_calendar_date(), + /// date!(2019-01-01).to_calendar_date(), /// (2019, Month::January, 1) /// ); /// ``` @@ -469,7 +469,7 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).to_ordinal_date(), (2019, 1)); + /// assert_eq!(date!(2019-01-01).to_ordinal_date(), (2019, 1)); /// ``` pub const fn to_ordinal_date(self) -> (i32, u16) { (self.year(), self.ordinal()) @@ -480,17 +480,11 @@ impl Date { /// ```rust /// # use time::Weekday::*; /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).to_iso_week_date(), (2019, 1, Tuesday)); - /// assert_eq!(date!(2019 - 10 - 04).to_iso_week_date(), (2019, 40, Friday)); - /// assert_eq!( - /// date!(2020 - 01 - 01).to_iso_week_date(), - /// (2020, 1, Wednesday) - /// ); - /// assert_eq!( - /// date!(2020 - 12 - 31).to_iso_week_date(), - /// (2020, 53, Thursday) - /// ); - /// assert_eq!(date!(2021 - 01 - 01).to_iso_week_date(), (2020, 53, Friday)); + /// assert_eq!(date!(2019-01-01).to_iso_week_date(), (2019, 1, Tuesday)); + /// assert_eq!(date!(2019-10-04).to_iso_week_date(), (2019, 40, Friday)); + /// assert_eq!(date!(2020-01-01).to_iso_week_date(), (2020, 1, Wednesday)); + /// assert_eq!(date!(2020-12-31).to_iso_week_date(), (2020, 53, Thursday)); + /// assert_eq!(date!(2021-01-01).to_iso_week_date(), (2020, 53, Friday)); /// ``` pub const fn to_iso_week_date(self) -> (i32, u8, Weekday) { let (year, ordinal) = self.to_ordinal_date(); @@ -508,18 +502,18 @@ impl Date { /// ```rust /// # use time::Weekday::*; /// # use time_macros::date; - /// assert_eq!(date!(2019 - 01 - 01).weekday(), Tuesday); - /// assert_eq!(date!(2019 - 02 - 01).weekday(), Friday); - /// assert_eq!(date!(2019 - 03 - 01).weekday(), Friday); - /// assert_eq!(date!(2019 - 04 - 01).weekday(), Monday); - /// assert_eq!(date!(2019 - 05 - 01).weekday(), Wednesday); - /// assert_eq!(date!(2019 - 06 - 01).weekday(), Saturday); - /// assert_eq!(date!(2019 - 07 - 01).weekday(), Monday); - /// assert_eq!(date!(2019 - 08 - 01).weekday(), Thursday); - /// assert_eq!(date!(2019 - 09 - 01).weekday(), Sunday); - /// assert_eq!(date!(2019 - 10 - 01).weekday(), Tuesday); - /// assert_eq!(date!(2019 - 11 - 01).weekday(), Friday); - /// assert_eq!(date!(2019 - 12 - 01).weekday(), Sunday); + /// assert_eq!(date!(2019-01-01).weekday(), Tuesday); + /// assert_eq!(date!(2019-02-01).weekday(), Friday); + /// assert_eq!(date!(2019-03-01).weekday(), Friday); + /// assert_eq!(date!(2019-04-01).weekday(), Monday); + /// assert_eq!(date!(2019-05-01).weekday(), Wednesday); + /// assert_eq!(date!(2019-06-01).weekday(), Saturday); + /// assert_eq!(date!(2019-07-01).weekday(), Monday); + /// assert_eq!(date!(2019-08-01).weekday(), Thursday); + /// assert_eq!(date!(2019-09-01).weekday(), Sunday); + /// assert_eq!(date!(2019-10-01).weekday(), Tuesday); + /// assert_eq!(date!(2019-11-01).weekday(), Friday); + /// assert_eq!(date!(2019-12-01).weekday(), Sunday); /// ``` pub const fn weekday(self) -> Weekday { match self.to_julian_day() % 7 { @@ -541,18 +535,9 @@ impl Date { /// ```rust /// # use time::Date; /// # use time_macros::date; - /// assert_eq!( - /// date!(2019 - 01 - 01).next_day(), - /// Some(date!(2019 - 01 - 02)) - /// ); - /// assert_eq!( - /// date!(2019 - 01 - 31).next_day(), - /// Some(date!(2019 - 02 - 01)) - /// ); - /// assert_eq!( - /// date!(2019 - 12 - 31).next_day(), - /// Some(date!(2020 - 01 - 01)) - /// ); + /// assert_eq!(date!(2019-01-01).next_day(), Some(date!(2019-01-02))); + /// assert_eq!(date!(2019-01-31).next_day(), Some(date!(2019-02-01))); + /// assert_eq!(date!(2019-12-31).next_day(), Some(date!(2020-01-01))); /// assert_eq!(Date::MAX.next_day(), None); /// ``` pub const fn next_day(self) -> Option { @@ -576,18 +561,9 @@ impl Date { /// ```rust /// # use time::Date; /// # use time_macros::date; - /// assert_eq!( - /// date!(2019 - 01 - 02).previous_day(), - /// Some(date!(2019 - 01 - 01)) - /// ); - /// assert_eq!( - /// date!(2019 - 02 - 01).previous_day(), - /// Some(date!(2019 - 01 - 31)) - /// ); - /// assert_eq!( - /// date!(2020 - 01 - 01).previous_day(), - /// Some(date!(2019 - 12 - 31)) - /// ); + /// assert_eq!(date!(2019-01-02).previous_day(), Some(date!(2019-01-01))); + /// assert_eq!(date!(2019-02-01).previous_day(), Some(date!(2019-01-31))); + /// assert_eq!(date!(2020-01-01).previous_day(), Some(date!(2019-12-31))); /// assert_eq!(Date::MIN.previous_day(), None); /// ``` pub const fn previous_day(self) -> Option { @@ -616,12 +592,12 @@ impl Date { /// # use time::Weekday; /// # use time_macros::date; /// assert_eq!( - /// date!(2023 - 06 - 28).next_occurrence(Weekday::Monday), - /// date!(2023 - 07 - 03) + /// date!(2023-06-28).next_occurrence(Weekday::Monday), + /// date!(2023-07-03) /// ); /// assert_eq!( - /// date!(2023 - 06 - 19).next_occurrence(Weekday::Monday), - /// date!(2023 - 06 - 26) + /// date!(2023-06-19).next_occurrence(Weekday::Monday), + /// date!(2023-06-26) /// ); /// ``` pub const fn next_occurrence(self, weekday: Weekday) -> Self { @@ -641,12 +617,12 @@ impl Date { /// # use time::Weekday; /// # use time_macros::date; /// assert_eq!( - /// date!(2023 - 06 - 28).prev_occurrence(Weekday::Monday), - /// date!(2023 - 06 - 26) + /// date!(2023-06-28).prev_occurrence(Weekday::Monday), + /// date!(2023-06-26) /// ); /// assert_eq!( - /// date!(2023 - 06 - 19).prev_occurrence(Weekday::Monday), - /// date!(2023 - 06 - 12) + /// date!(2023-06-19).prev_occurrence(Weekday::Monday), + /// date!(2023-06-12) /// ); /// ``` pub const fn prev_occurrence(self, weekday: Weekday) -> Self { @@ -666,12 +642,12 @@ impl Date { /// # use time::Weekday; /// # use time_macros::date; /// assert_eq!( - /// date!(2023 - 06 - 25).nth_next_occurrence(Weekday::Monday, 5), - /// date!(2023 - 07 - 24) + /// date!(2023-06-25).nth_next_occurrence(Weekday::Monday, 5), + /// date!(2023-07-24) /// ); /// assert_eq!( - /// date!(2023 - 06 - 26).nth_next_occurrence(Weekday::Monday, 5), - /// date!(2023 - 07 - 31) + /// date!(2023-06-26).nth_next_occurrence(Weekday::Monday, 5), + /// date!(2023-07-31) /// ); /// ``` pub const fn nth_next_occurrence(self, weekday: Weekday, n: u8) -> Self { @@ -691,12 +667,12 @@ impl Date { /// # use time::Weekday; /// # use time_macros::date; /// assert_eq!( - /// date!(2023 - 06 - 27).nth_prev_occurrence(Weekday::Monday, 3), - /// date!(2023 - 06 - 12) + /// date!(2023-06-27).nth_prev_occurrence(Weekday::Monday, 3), + /// date!(2023-06-12) /// ); /// assert_eq!( - /// date!(2023 - 06 - 26).nth_prev_occurrence(Weekday::Monday, 3), - /// date!(2023 - 06 - 05) + /// date!(2023-06-26).nth_prev_occurrence(Weekday::Monday, 3), + /// date!(2023-06-05) /// ); /// ``` pub const fn nth_prev_occurrence(self, weekday: Weekday, n: u8) -> Self { @@ -714,9 +690,9 @@ impl Date { /// ```rust /// # use time_macros::date; /// assert_eq!(date!(-4713 - 11 - 24).to_julian_day(), 0); - /// assert_eq!(date!(2000 - 01 - 01).to_julian_day(), 2_451_545); - /// assert_eq!(date!(2019 - 01 - 01).to_julian_day(), 2_458_485); - /// assert_eq!(date!(2019 - 12 - 31).to_julian_day(), 2_458_849); + /// assert_eq!(date!(2000-01-01).to_julian_day(), 2_451_545); + /// assert_eq!(date!(2019-01-01).to_julian_day(), 2_458_485); + /// assert_eq!(date!(2019-12-31).to_julian_day(), 2_458_849); /// ``` pub const fn to_julian_day(self) -> i32 { let year = self.year() - 1; @@ -737,8 +713,8 @@ impl Date { /// assert_eq!(Date::MAX.checked_add(1.days()), None); /// assert_eq!(Date::MIN.checked_add((-2).days()), None); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add(2.days()), - /// Some(date!(2021 - 01 - 02)) + /// date!(2020-12-31).checked_add(2.days()), + /// Some(date!(2021-01-02)) /// ); /// ``` /// @@ -752,12 +728,12 @@ impl Date { /// assert_eq!(Date::MAX.checked_add(23.hours()), Some(Date::MAX)); /// assert_eq!(Date::MIN.checked_add((-23).hours()), Some(Date::MIN)); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add(23.hours()), - /// Some(date!(2020 - 12 - 31)) + /// date!(2020-12-31).checked_add(23.hours()), + /// Some(date!(2020-12-31)) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add(47.hours()), - /// Some(date!(2021 - 01 - 01)) + /// date!(2020-12-31).checked_add(47.hours()), + /// Some(date!(2021-01-01)) /// ); /// ``` pub const fn checked_add(self, duration: Duration) -> Option { @@ -781,8 +757,8 @@ impl Date { /// # use time_macros::date; /// assert_eq!(Date::MAX.checked_add_std(1.std_days()), None); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add_std(2.std_days()), - /// Some(date!(2021 - 01 - 02)) + /// date!(2020-12-31).checked_add_std(2.std_days()), + /// Some(date!(2021-01-02)) /// ); /// ``` /// @@ -795,12 +771,12 @@ impl Date { /// # use time_macros::date; /// assert_eq!(Date::MAX.checked_add_std(23.std_hours()), Some(Date::MAX)); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add_std(23.std_hours()), - /// Some(date!(2020 - 12 - 31)) + /// date!(2020-12-31).checked_add_std(23.std_hours()), + /// Some(date!(2020-12-31)) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_add_std(47.std_hours()), - /// Some(date!(2021 - 01 - 01)) + /// date!(2020-12-31).checked_add_std(47.std_hours()), + /// Some(date!(2021-01-01)) /// ); /// ``` pub const fn checked_add_std(self, duration: StdDuration) -> Option { @@ -825,8 +801,8 @@ impl Date { /// assert_eq!(Date::MAX.checked_sub((-2).days()), None); /// assert_eq!(Date::MIN.checked_sub(1.days()), None); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub(2.days()), - /// Some(date!(2020 - 12 - 29)) + /// date!(2020-12-31).checked_sub(2.days()), + /// Some(date!(2020-12-29)) /// ); /// ``` /// @@ -840,12 +816,12 @@ impl Date { /// assert_eq!(Date::MAX.checked_sub((-23).hours()), Some(Date::MAX)); /// assert_eq!(Date::MIN.checked_sub(23.hours()), Some(Date::MIN)); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub(23.hours()), - /// Some(date!(2020 - 12 - 31)) + /// date!(2020-12-31).checked_sub(23.hours()), + /// Some(date!(2020-12-31)) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub(47.hours()), - /// Some(date!(2020 - 12 - 30)) + /// date!(2020-12-31).checked_sub(47.hours()), + /// Some(date!(2020-12-30)) /// ); /// ``` pub const fn checked_sub(self, duration: Duration) -> Option { @@ -869,8 +845,8 @@ impl Date { /// # use time_macros::date; /// assert_eq!(Date::MIN.checked_sub_std(1.std_days()), None); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub_std(2.std_days()), - /// Some(date!(2020 - 12 - 29)) + /// date!(2020-12-31).checked_sub_std(2.std_days()), + /// Some(date!(2020-12-29)) /// ); /// ``` /// @@ -883,12 +859,12 @@ impl Date { /// # use time_macros::date; /// assert_eq!(Date::MIN.checked_sub_std(23.std_hours()), Some(Date::MIN)); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub_std(23.std_hours()), - /// Some(date!(2020 - 12 - 31)) + /// date!(2020-12-31).checked_sub_std(23.std_hours()), + /// Some(date!(2020-12-31)) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).checked_sub_std(47.std_hours()), - /// Some(date!(2020 - 12 - 30)) + /// date!(2020-12-31).checked_sub_std(47.std_hours()), + /// Some(date!(2020-12-30)) /// ); /// ``` pub const fn checked_sub_std(self, duration: StdDuration) -> Option { @@ -975,8 +951,8 @@ impl Date { /// assert_eq!(Date::MAX.saturating_add(1.days()), Date::MAX); /// assert_eq!(Date::MIN.saturating_add((-2).days()), Date::MIN); /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_add(2.days()), - /// date!(2021 - 01 - 02) + /// date!(2020-12-31).saturating_add(2.days()), + /// date!(2021-01-02) /// ); /// ``` /// @@ -988,12 +964,12 @@ impl Date { /// # use time::ext::NumericalDuration; /// # use time_macros::date; /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_add(23.hours()), - /// date!(2020 - 12 - 31) + /// date!(2020-12-31).saturating_add(23.hours()), + /// date!(2020-12-31) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_add(47.hours()), - /// date!(2021 - 01 - 01) + /// date!(2020-12-31).saturating_add(47.hours()), + /// date!(2021-01-01) /// ); /// ``` pub const fn saturating_add(self, duration: Duration) -> Self { @@ -1015,8 +991,8 @@ impl Date { /// assert_eq!(Date::MAX.saturating_sub((-2).days()), Date::MAX); /// assert_eq!(Date::MIN.saturating_sub(1.days()), Date::MIN); /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_sub(2.days()), - /// date!(2020 - 12 - 29) + /// date!(2020-12-31).saturating_sub(2.days()), + /// date!(2020-12-29) /// ); /// ``` /// @@ -1028,12 +1004,12 @@ impl Date { /// # use time::ext::NumericalDuration; /// # use time_macros::date; /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_sub(23.hours()), - /// date!(2020 - 12 - 31) + /// date!(2020-12-31).saturating_sub(23.hours()), + /// date!(2020-12-31) /// ); /// assert_eq!( - /// date!(2020 - 12 - 31).saturating_sub(47.hours()), - /// date!(2020 - 12 - 30) + /// date!(2020-12-31).saturating_sub(47.hours()), + /// date!(2020-12-30) /// ); /// ``` pub const fn saturating_sub(self, duration: Duration) -> Self { @@ -1054,11 +1030,11 @@ impl Date { /// ```rust /// # use time_macros::date; /// assert_eq!( - /// date!(2022 - 02 - 18).replace_year(2019), - /// Ok(date!(2019 - 02 - 18)) + /// date!(2022-02-18).replace_year(2019), + /// Ok(date!(2019-02-18)) /// ); - /// assert!(date!(2022 - 02 - 18).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year - /// assert!(date!(2022 - 02 - 18).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year + /// assert!(date!(2022-02-18).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year + /// assert!(date!(2022-02-18).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year /// ``` #[must_use = "This method does not mutate the original `Date`."] pub const fn replace_year(self, year: i32) -> Result { @@ -1102,10 +1078,10 @@ impl Date { /// # use time_macros::date; /// # use time::Month; /// assert_eq!( - /// date!(2022 - 02 - 18).replace_month(Month::January), - /// Ok(date!(2022 - 01 - 18)) + /// date!(2022-02-18).replace_month(Month::January), + /// Ok(date!(2022-01-18)) /// ); - /// assert!(date!(2022 - 01 - 30) + /// assert!(date!(2022-01-30) /// .replace_month(Month::February) /// .is_err()); // 30 isn't a valid day in February /// ``` @@ -1119,12 +1095,9 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!( - /// date!(2022 - 02 - 18).replace_day(1), - /// Ok(date!(2022 - 02 - 01)) - /// ); - /// assert!(date!(2022 - 02 - 18).replace_day(0).is_err()); // 0 isn't a valid day - /// assert!(date!(2022 - 02 - 18).replace_day(30).is_err()); // 30 isn't a valid day in February + /// assert_eq!(date!(2022-02-18).replace_day(1), Ok(date!(2022-02-01))); + /// assert!(date!(2022-02-18).replace_day(0).is_err()); // 0 isn't a valid day + /// assert!(date!(2022-02-18).replace_day(30).is_err()); // 30 isn't a valid day in February /// ``` #[must_use = "This method does not mutate the original `Date`."] pub const fn replace_day(self, day: u8) -> Result { @@ -1155,9 +1128,9 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert_eq!(date!(2022 - 049).replace_ordinal(1), Ok(date!(2022 - 001))); - /// assert!(date!(2022 - 049).replace_ordinal(0).is_err()); // 0 isn't a valid ordinal - /// assert!(date!(2022 - 049).replace_ordinal(366).is_err()); // 2022 isn't a leap year + /// assert_eq!(date!(2022-049).replace_ordinal(1), Ok(date!(2022-001))); + /// assert!(date!(2022-049).replace_ordinal(0).is_err()); // 0 isn't a valid ordinal + /// assert!(date!(2022-049).replace_ordinal(366).is_err()); // 2022 isn't a leap year /// ```` #[must_use = "This method does not mutate the original `Date`."] pub const fn replace_ordinal(self, ordinal: u16) -> Result { @@ -1212,8 +1185,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert!(date!(1970 - 01 - 01).with_hms(0, 0, 0).is_ok()); - /// assert!(date!(1970 - 01 - 01).with_hms(24, 0, 0).is_err()); + /// assert!(date!(1970-01-01).with_hms(0, 0, 0).is_ok()); + /// assert!(date!(1970-01-01).with_hms(24, 0, 0).is_err()); /// ``` pub const fn with_hms( self, @@ -1231,8 +1204,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert!(date!(1970 - 01 - 01).with_hms_milli(0, 0, 0, 0).is_ok()); - /// assert!(date!(1970 - 01 - 01).with_hms_milli(24, 0, 0, 0).is_err()); + /// assert!(date!(1970-01-01).with_hms_milli(0, 0, 0, 0).is_ok()); + /// assert!(date!(1970-01-01).with_hms_milli(24, 0, 0, 0).is_err()); /// ``` pub const fn with_hms_milli( self, @@ -1251,8 +1224,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert!(date!(1970 - 01 - 01).with_hms_micro(0, 0, 0, 0).is_ok()); - /// assert!(date!(1970 - 01 - 01).with_hms_micro(24, 0, 0, 0).is_err()); + /// assert!(date!(1970-01-01).with_hms_micro(0, 0, 0, 0).is_ok()); + /// assert!(date!(1970-01-01).with_hms_micro(24, 0, 0, 0).is_err()); /// ``` pub const fn with_hms_micro( self, @@ -1271,8 +1244,8 @@ impl Date { /// /// ```rust /// # use time_macros::date; - /// assert!(date!(1970 - 01 - 01).with_hms_nano(0, 0, 0, 0).is_ok()); - /// assert!(date!(1970 - 01 - 01).with_hms_nano(24, 0, 0, 0).is_err()); + /// assert!(date!(1970-01-01).with_hms_nano(0, 0, 0, 0).is_ok()); + /// assert!(date!(1970-01-01).with_hms_nano(24, 0, 0, 0).is_err()); /// ``` pub const fn with_hms_nano( self, @@ -1307,7 +1280,7 @@ impl Date { /// # use time::{format_description}; /// # use time_macros::date; /// let format = format_description::parse("[year]-[month]-[day]")?; - /// assert_eq!(date!(2020 - 01 - 02).format(&format)?, "2020-01-02"); + /// assert_eq!(date!(2020-01-02).format(&format)?, "2020-01-02"); /// # Ok::<_, time::Error>(()) /// ``` pub fn format(self, format: &(impl Formattable + ?Sized)) -> Result { @@ -1324,7 +1297,7 @@ impl Date { /// # use time::Date; /// # use time_macros::{date, format_description}; /// let format = format_description!("[year]-[month]-[day]"); - /// assert_eq!(Date::parse("2020-01-02", &format)?, date!(2020 - 01 - 02)); + /// assert_eq!(Date::parse("2020-01-02", &format)?, date!(2020-01-02)); /// # Ok::<_, time::Error>(()) /// ``` pub fn parse( diff --git a/time/src/format_description/parse/format_item.rs b/time/src/format_description/parse/format_item.rs index 7a75006c66..46b01bca8b 100644 --- a/time/src/format_description/parse/format_item.rs +++ b/time/src/format_description/parse/format_item.rs @@ -259,7 +259,7 @@ macro_rules! component_definition { ) -> Result { $(#[allow(clippy::string_lit_as_bytes)] if name.eq_ignore_ascii_case($parse_variant.as_bytes()) { - return Ok(Component::$variant($variant::with_modifiers(&modifiers, name.span)?,)); + return Ok(Component::$variant($variant::with_modifiers(&modifiers, name.span)?)); })* Err(Error { _inner: unused(name.span.error("invalid component")), diff --git a/time/src/macros.rs b/time/src/macros.rs index d788645683..4167f32464 100644 --- a/time/src/macros.rs +++ b/time/src/macros.rs @@ -12,9 +12,9 @@ /// date!(2020 - W 01 - 3), /// Date::from_iso_week_date(2020, 1, Wednesday)? /// ); -/// assert_eq!(date!(2020 - 001), Date::from_ordinal_date(2020, 1)?); +/// assert_eq!(date!(2020-001), Date::from_ordinal_date(2020, 1)?); /// assert_eq!( -/// date!(2020 - 01 - 01), +/// date!(2020-01-01), /// Date::from_calendar_date(2020, Month::January, 1)? /// ); /// # Ok::<_, time::Error>(()) @@ -65,7 +65,7 @@ pub use time_macros::datetime; /// ); /// # Ok::<_, time::Error>(()) /// ``` -/// +/// /// The syntax accepted by this macro is the same as [`format_description::parse()`], which can /// be found in [the book](https://time-rs.github.io/book/api/format-description.html). /// diff --git a/time/src/offset_date_time.rs b/time/src/offset_date_time.rs index 26043eec9e..9b478a79cc 100644 --- a/time/src/offset_date_time.rs +++ b/time/src/offset_date_time.rs @@ -74,7 +74,7 @@ impl OffsetDateTime { /// ```rust /// # use time::OffsetDateTime; /// # use time_macros::datetime; - /// assert_eq!(OffsetDateTime::UNIX_EPOCH, datetime!(1970-01-01 0:00 UTC),); + /// assert_eq!(OffsetDateTime::UNIX_EPOCH, datetime!(1970-01-01 0:00 UTC)); /// ``` pub const UNIX_EPOCH: Self = Self::new_in_offset( // Safety: `ordinal` is not zero. @@ -846,8 +846,8 @@ impl OffsetDateTime { /// assert_eq!(datetime.checked_add(2.days()), None); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30 +10).checked_add(27.hours()), - /// Some(datetime!(2019 - 11 - 26 18:30 +10)) + /// datetime!(2019-11-25 15:30 +10).checked_add(27.hours()), + /// Some(datetime!(2019-11-26 18:30 +10)) /// ); /// ``` pub const fn checked_add(self, duration: Duration) -> Option { @@ -866,8 +866,8 @@ impl OffsetDateTime { /// assert_eq!(datetime.checked_sub((-2).days()), None); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30 +10).checked_sub(27.hours()), - /// Some(datetime!(2019 - 11 - 24 12:30 +10)) + /// datetime!(2019-11-25 15:30 +10).checked_sub(27.hours()), + /// Some(datetime!(2019-11-24 12:30 +10)) /// ); /// ``` pub const fn checked_sub(self, duration: Duration) -> Option { @@ -917,8 +917,8 @@ impl OffsetDateTime { /// ); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30 +10).saturating_add(27.hours()), - /// datetime!(2019 - 11 - 26 18:30 +10) + /// datetime!(2019-11-25 15:30 +10).saturating_add(27.hours()), + /// datetime!(2019-11-26 18:30 +10) /// ); /// ``` pub const fn saturating_add(self, duration: Duration) -> Self { @@ -972,8 +972,8 @@ impl OffsetDateTime { /// ); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30 +10).saturating_sub(27.hours()), - /// datetime!(2019 - 11 - 24 12:30 +10) + /// datetime!(2019-11-25 15:30 +10).saturating_sub(27.hours()), + /// datetime!(2019-11-24 12:30 +10) /// ); /// ``` pub const fn saturating_sub(self, duration: Duration) -> Self { @@ -1071,11 +1071,11 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00 +01).replace_year(2019), - /// Ok(datetime!(2019 - 02 - 18 12:00 +01)) + /// datetime!(2022-02-18 12:00 +01).replace_year(2019), + /// Ok(datetime!(2019-02-18 12:00 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year - /// assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year + /// assert!(datetime!(2022-02-18 12:00 +01).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year + /// assert!(datetime!(2022-02-18 12:00 +01).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_year(self, year: i32) -> Result { @@ -1088,10 +1088,10 @@ impl OffsetDateTime { /// # use time_macros::datetime; /// # use time::Month; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00 +01).replace_month(Month::January), - /// Ok(datetime!(2022 - 01 - 18 12:00 +01)) + /// datetime!(2022-02-18 12:00 +01).replace_month(Month::January), + /// Ok(datetime!(2022-01-18 12:00 +01)) /// ); - /// assert!(datetime!(2022 - 01 - 30 12:00 +01).replace_month(Month::February).is_err()); // 30 isn't a valid day in February + /// assert!(datetime!(2022-01-30 12:00 +01).replace_month(Month::February).is_err()); // 30 isn't a valid day in February /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_month(self, month: Month) -> Result { @@ -1103,11 +1103,11 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00 +01).replace_day(1), - /// Ok(datetime!(2022 - 02 - 01 12:00 +01)) + /// datetime!(2022-02-18 12:00 +01).replace_day(1), + /// Ok(datetime!(2022-02-01 12:00 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_day(0).is_err()); // 00 isn't a valid day - /// assert!(datetime!(2022 - 02 - 18 12:00 +01).replace_day(30).is_err()); // 30 isn't a valid day in February + /// assert!(datetime!(2022-02-18 12:00 +01).replace_day(0).is_err()); // 00 isn't a valid day + /// assert!(datetime!(2022-02-18 12:00 +01).replace_day(30).is_err()); // 30 isn't a valid day in February /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_day(self, day: u8) -> Result { @@ -1132,10 +1132,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_hour(7), - /// Ok(datetime!(2022 - 02 - 18 07:02:03.004_005_006 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_hour(7), + /// Ok(datetime!(2022-02-18 07:02:03.004_005_006 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_hour(24).is_err()); // 24 isn't a valid hour + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_hour(24).is_err()); // 24 isn't a valid hour /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_hour(self, hour: u8) -> Result { @@ -1147,10 +1147,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_minute(7), - /// Ok(datetime!(2022 - 02 - 18 01:07:03.004_005_006 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_minute(7), + /// Ok(datetime!(2022-02-18 01:07:03.004_005_006 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_minute(60).is_err()); // 60 isn't a valid minute + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_minute(60).is_err()); // 60 isn't a valid minute /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_minute(self, minute: u8) -> Result { @@ -1162,10 +1162,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_second(7), - /// Ok(datetime!(2022 - 02 - 18 01:02:07.004_005_006 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_second(7), + /// Ok(datetime!(2022-02-18 01:02:07.004_005_006 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_second(60).is_err()); // 60 isn't a valid second + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_second(60).is_err()); // 60 isn't a valid second /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_second(self, second: u8) -> Result { @@ -1177,10 +1177,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_millisecond(7), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_millisecond(7), + /// Ok(datetime!(2022-02-18 01:02:03.007 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_millisecond(1_000).is_err()); // 1_000 isn't a valid millisecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_millisecond(1_000).is_err()); // 1_000 isn't a valid millisecond /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_millisecond( @@ -1198,10 +1198,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_microsecond(7_008), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007_008 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_microsecond(7_008), + /// Ok(datetime!(2022-02-18 01:02:03.007_008 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_microsecond(1_000_000).is_err()); // 1_000_000 isn't a valid microsecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_microsecond(1_000_000).is_err()); // 1_000_000 isn't a valid microsecond /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_microsecond( @@ -1219,10 +1219,10 @@ impl OffsetDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_nanosecond(7_008_009), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007_008_009 +01)) + /// datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_nanosecond(7_008_009), + /// Ok(datetime!(2022-02-18 01:02:03.007_008_009 +01)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006 +01).replace_nanosecond(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006 +01).replace_nanosecond(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond /// ``` #[must_use = "This method does not mutate the original `OffsetDateTime`."] pub const fn replace_nanosecond(self, nanosecond: u32) -> Result { diff --git a/time/src/primitive_date_time.rs b/time/src/primitive_date_time.rs index 85ae075e80..e7ca99dddf 100644 --- a/time/src/primitive_date_time.rs +++ b/time/src/primitive_date_time.rs @@ -506,8 +506,8 @@ impl PrimitiveDateTime { /// assert_eq!(datetime.checked_add(1.days()), None); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30).checked_add(27.hours()), - /// Some(datetime!(2019 - 11 - 26 18:30)) + /// datetime!(2019-11-25 15:30).checked_add(27.hours()), + /// Some(datetime!(2019-11-26 18:30)) /// ); /// ``` pub const fn checked_add(self, duration: Duration) -> Option { @@ -536,8 +536,8 @@ impl PrimitiveDateTime { /// assert_eq!(datetime.checked_sub((-1).days()), None); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30).checked_sub(27.hours()), - /// Some(datetime!(2019 - 11 - 24 12:30)) + /// datetime!(2019-11-25 15:30).checked_sub(27.hours()), + /// Some(datetime!(2019-11-24 12:30)) /// ); /// ``` pub const fn checked_sub(self, duration: Duration) -> Option { @@ -572,8 +572,8 @@ impl PrimitiveDateTime { /// ); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30).saturating_add(27.hours()), - /// datetime!(2019 - 11 - 26 18:30) + /// datetime!(2019-11-25 15:30).saturating_add(27.hours()), + /// datetime!(2019-11-26 18:30) /// ); /// ``` pub const fn saturating_add(self, duration: Duration) -> Self { @@ -602,8 +602,8 @@ impl PrimitiveDateTime { /// ); /// /// assert_eq!( - /// datetime!(2019 - 11 - 25 15:30).saturating_sub(27.hours()), - /// datetime!(2019 - 11 - 24 12:30) + /// datetime!(2019-11-25 15:30).saturating_sub(27.hours()), + /// datetime!(2019-11-24 12:30) /// ); /// ``` pub const fn saturating_sub(self, duration: Duration) -> Self { @@ -660,11 +660,11 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00).replace_year(2019), - /// Ok(datetime!(2019 - 02 - 18 12:00)) + /// datetime!(2022-02-18 12:00).replace_year(2019), + /// Ok(datetime!(2019-02-18 12:00)) /// ); - /// assert!(datetime!(2022 - 02 - 18 12:00).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year - /// assert!(datetime!(2022 - 02 - 18 12:00).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year + /// assert!(datetime!(2022-02-18 12:00).replace_year(-1_000_000_000).is_err()); // -1_000_000_000 isn't a valid year + /// assert!(datetime!(2022-02-18 12:00).replace_year(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid year /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_year(self, year: i32) -> Result { @@ -680,10 +680,10 @@ impl PrimitiveDateTime { /// # use time_macros::datetime; /// # use time::Month; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00).replace_month(Month::January), - /// Ok(datetime!(2022 - 01 - 18 12:00)) + /// datetime!(2022-02-18 12:00).replace_month(Month::January), + /// Ok(datetime!(2022-01-18 12:00)) /// ); - /// assert!(datetime!(2022 - 01 - 30 12:00).replace_month(Month::February).is_err()); // 30 isn't a valid day in February + /// assert!(datetime!(2022-01-30 12:00).replace_month(Month::February).is_err()); // 30 isn't a valid day in February /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_month(self, month: Month) -> Result { @@ -698,11 +698,11 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 12:00).replace_day(1), - /// Ok(datetime!(2022 - 02 - 01 12:00)) + /// datetime!(2022-02-18 12:00).replace_day(1), + /// Ok(datetime!(2022-02-01 12:00)) /// ); - /// assert!(datetime!(2022 - 02 - 18 12:00).replace_day(0).is_err()); // 00 isn't a valid day - /// assert!(datetime!(2022 - 02 - 18 12:00).replace_day(30).is_err()); // 30 isn't a valid day in February + /// assert!(datetime!(2022-02-18 12:00).replace_day(0).is_err()); // 00 isn't a valid day + /// assert!(datetime!(2022-02-18 12:00).replace_day(30).is_err()); // 30 isn't a valid day in February /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_day(self, day: u8) -> Result { @@ -733,10 +733,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_hour(7), - /// Ok(datetime!(2022 - 02 - 18 07:02:03.004_005_006)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_hour(7), + /// Ok(datetime!(2022-02-18 07:02:03.004_005_006)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_hour(24).is_err()); // 24 isn't a valid hour + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_hour(24).is_err()); // 24 isn't a valid hour /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_hour(self, hour: u8) -> Result { @@ -751,10 +751,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_minute(7), - /// Ok(datetime!(2022 - 02 - 18 01:07:03.004_005_006)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_minute(7), + /// Ok(datetime!(2022-02-18 01:07:03.004_005_006)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_minute(60).is_err()); // 60 isn't a valid minute + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_minute(60).is_err()); // 60 isn't a valid minute /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_minute(self, minute: u8) -> Result { @@ -769,10 +769,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_second(7), - /// Ok(datetime!(2022 - 02 - 18 01:02:07.004_005_006)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_second(7), + /// Ok(datetime!(2022-02-18 01:02:07.004_005_006)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_second(60).is_err()); // 60 isn't a valid second + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_second(60).is_err()); // 60 isn't a valid second /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_second(self, second: u8) -> Result { @@ -787,10 +787,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_millisecond(7), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_millisecond(7), + /// Ok(datetime!(2022-02-18 01:02:03.007)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_millisecond(1_000).is_err()); // 1_000 isn't a valid millisecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_millisecond(1_000).is_err()); // 1_000 isn't a valid millisecond /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_millisecond( @@ -808,10 +808,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_microsecond(7_008), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007_008)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_microsecond(7_008), + /// Ok(datetime!(2022-02-18 01:02:03.007_008)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_microsecond(1_000_000).is_err()); // 1_000_000 isn't a valid microsecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_microsecond(1_000_000).is_err()); // 1_000_000 isn't a valid microsecond /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_microsecond( @@ -829,10 +829,10 @@ impl PrimitiveDateTime { /// ```rust /// # use time_macros::datetime; /// assert_eq!( - /// datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_nanosecond(7_008_009), - /// Ok(datetime!(2022 - 02 - 18 01:02:03.007_008_009)) + /// datetime!(2022-02-18 01:02:03.004_005_006).replace_nanosecond(7_008_009), + /// Ok(datetime!(2022-02-18 01:02:03.007_008_009)) /// ); - /// assert!(datetime!(2022 - 02 - 18 01:02:03.004_005_006).replace_nanosecond(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond + /// assert!(datetime!(2022-02-18 01:02:03.004_005_006).replace_nanosecond(1_000_000_000).is_err()); // 1_000_000_000 isn't a valid nanosecond /// ``` #[must_use = "This method does not mutate the original `PrimitiveDateTime`."] pub const fn replace_nanosecond(self, nanosecond: u32) -> Result { diff --git a/time/src/serde/mod.rs b/time/src/serde/mod.rs index f7ac731083..6a2af3be57 100644 --- a/time/src/serde/mod.rs +++ b/time/src/serde/mod.rs @@ -205,7 +205,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// ``` /// /// [`format_description::parse()`]: crate::format_description::parse() -#[cfg(all(feature = "macros", any(feature = "formatting", feature = "parsing"),))] +#[cfg(all(feature = "macros", any(feature = "formatting", feature = "parsing")))] pub use time_macros::serde_format_description as format_description; use self::visitor::Visitor;