Skip to content

Commit

Permalink
Created tests by cloning tests for YearRepr::Full and YearRepr::LastT…
Browse files Browse the repository at this point in the history
…wo; cargo fmt
  • Loading branch information
dennisorlando committed Sep 25, 2024
1 parent aba2bc2 commit 846c82d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions tests/parse_format_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: _,
Expand Down
21 changes: 21 additions & 0 deletions tests/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion time/src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion time/src/parsing/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn parse_year(input: &[u8], modifiers: modifier::Year) -> Option<Pars
_ => 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(
Expand Down
11 changes: 4 additions & 7 deletions time/src/parsing/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit 846c82d

Please sign in to comment.