From 846c82db132231c25778d97a1978733607b62c63 Mon Sep 17 00:00:00 2001 From: Dennis Orlando Date: Wed, 25 Sep 2024 17:12:47 +0200 Subject: [PATCH] Created tests by cloning tests for YearRepr::Full and YearRepr::LastTwo; cargo fmt --- tests/parse_format_description.rs | 1 + tests/parsing.rs | 21 +++++++++++++++++++++ time/src/formatting/mod.rs | 1 - time/src/parsing/component.rs | 2 +- time/src/parsing/parsed.rs | 11 ++++------- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/parse_format_description.rs b/tests/parse_format_description.rs index f29233c93..0f4a9a085 100644 --- a/tests/parse_format_description.rs +++ b/tests/parse_format_description.rs @@ -78,6 +78,7 @@ fn modifiers( week_number_repr: _, #[values( (YearRepr::Full, "repr:full"), + (YearRepr::Four, "repr:four"), (YearRepr::LastTwo, "repr:last_two"), )] year_repr: _, diff --git a/tests/parsing.rs b/tests/parsing.rs index 518661d3b..8befb3d60 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -1141,6 +1141,17 @@ fn parse_components() -> time::Result<()> { b"2021", _.year() == Some(2021) ); + parse_component!( + Component::Year(modifier!(Year { + padding: modifier::Padding::Zero, + repr: modifier::YearRepr::Four, + iso_week_based: false, + sign_is_mandatory: false, + })), + b"2021", + _.year() == Some(2021) + ); +; parse_component!( Component::Year(modifier!(Year { padding: modifier::Padding::Zero, @@ -1161,6 +1172,16 @@ fn parse_components() -> time::Result<()> { b"2021", _.iso_year() == Some(2021) ); + parse_component!( + Component::Year(modifier!(Year { + padding: modifier::Padding::Zero, + repr: modifier::YearRepr::Four, + iso_week_based: true, + sign_is_mandatory: false, + })), + b"2021", + _.iso_year() == Some(2021) + ); parse_component!( Component::Year(modifier!(Year { padding: modifier::Padding::Zero, diff --git a/time/src/formatting/mod.rs b/time/src/formatting/mod.rs index 9f8efcf95..0e367bdea 100644 --- a/time/src/formatting/mod.rs +++ b/time/src/formatting/mod.rs @@ -308,7 +308,6 @@ fn fmt_year( modifier::YearRepr::LastTwo => (full_year % 100).abs(), }; let format_number = match repr { - #[cfg(feature = "large-dates")] modifier::YearRepr::Full if value.abs() >= 100_000 => format_number::<6>, #[cfg(feature = "large-dates")] diff --git a/time/src/parsing/component.rs b/time/src/parsing/component.rs index 8b631bd8b..fbaa896b2 100644 --- a/time/src/parsing/component.rs +++ b/time/src/parsing/component.rs @@ -32,7 +32,7 @@ pub(crate) fn parse_year(input: &[u8], modifiers: modifier::Year) -> Option Some(ParsedItem(input, year.cast_signed())), } } - modifier::YearRepr::Four => Some ( + modifier::YearRepr::Four => Some( exactly_n_digits_padded::<4, u32>(modifiers.padding)(input)?.map(|v| v.cast_signed()), ), modifier::YearRepr::LastTwo => Some( diff --git a/time/src/parsing/parsed.rs b/time/src/parsing/parsed.rs index 084e39978..be46b3be6 100644 --- a/time/src/parsing/parsed.rs +++ b/time/src/parsing/parsed.rs @@ -6,7 +6,8 @@ use deranged::{ OptionRangedI128, OptionRangedI32, OptionRangedI8, OptionRangedU16, OptionRangedU32, OptionRangedU8, RangedI128, RangedI32, RangedI8, RangedU16, RangedU32, RangedU8, }; -use num_conv::{prelude::*, CastUnsigned, Truncate}; +use num_conv::prelude::*; +use num_conv::{CastUnsigned, Truncate}; use crate::convert::{Day, Hour, Minute, Nanosecond, Second}; use crate::date::{MAX_YEAR, MIN_YEAR}; @@ -296,16 +297,12 @@ impl Parsed { parse_year(input, modifiers).ok_or(InvalidComponent("year"))?; match (modifiers.iso_week_based, modifiers.repr) { (false, modifier::YearRepr::Full) => self.set_year(value), - (false, modifier::YearRepr::Four) => { - self.set_year(value) - } + (false, modifier::YearRepr::Four) => self.set_year(value), (false, modifier::YearRepr::LastTwo) => { self.set_year_last_two(value.cast_unsigned().truncate()) } (true, modifier::YearRepr::Full) => self.set_iso_year(value), - (true, modifier::YearRepr::Four) => { - self.set_iso_year(value) - } + (true, modifier::YearRepr::Four) => self.set_iso_year(value), (true, modifier::YearRepr::LastTwo) => { self.set_iso_year_last_two(value.cast_unsigned().truncate()) }