Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 22, 2023
1 parent 54837ae commit c68d04d
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ impl<'a, J, Tz: TimeZone> FormattingSpec<DateTime<Tz>, J> {
}

Check warning on line 190 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L189-L190

Added lines #L189 - L190 were not covered by tests
}

impl<'a, Tz: TimeZone> FormattingSpec<DateTime<Tz>, &'a [Item<'a>]> {
// TODO: once our MSRV >= 1.61 change this impl to take a generic `Tz` trait bound.
// Trait bounds on const fn parameters were not supported before.
impl<'a> FormattingSpec<DateTime<Utc>, &'a [Item<'a>]> {
/// Creates a new `FormattingSpec` given a slice of [`Item`]'s.
///
/// The difference with the more generic [`FormattingSpec::from_items`] is that `from_slice` is
Expand Down Expand Up @@ -273,6 +275,37 @@ impl<'a, Tz: TimeZone> FormattingSpec<DateTime<Tz>, &'a [Item<'a>]> {
}

Check warning on line 275 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L274-L275

Added lines #L274 - L275 were not covered by tests
}

impl<'a> FormattingSpec<DateTime<FixedOffset>, &'a [Item<'a>]> {
/// Creates a new `FormattingSpec` given a slice of [`Item`]'s.
pub const fn from_slice(items: &'a [Item<'a>]) -> Result<Self, ParseError> {
let locale = locales::default_locale();
let mut i = 0;
while i < items.len() {
if let Err(e) = items[i].check_fields(true, true, true, locale) {
return Err(e);
}
i += 1;

Check warning on line 287 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L280-L287

Added lines #L280 - L287 were not covered by tests
}
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
}

Check warning on line 290 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L289-L290

Added lines #L289 - L290 were not covered by tests

/// Creates a new `FormattingSpec` given a slice of [`Item`]'s and a `locale`.
#[cfg(feature = "unstable-locales")]
pub const fn from_slice_localized(
items: &'a [Item<'a>],
locale: Locale,
) -> Result<Self, ParseError> {
let mut i = 0;
while i < items.len() {
if let Err(e) = items[i].check_fields(true, true, true, locale) {
return Err(e);
}
i += 1;

Check warning on line 303 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L294-L303

Added lines #L294 - L303 were not covered by tests
}
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
}

Check warning on line 306 in src/format/formatting.rs

View check run for this annotation

Codecov / codecov/patch

src/format/formatting.rs#L305-L306

Added lines #L305 - L306 were not covered by tests
}

macro_rules! formatting_spec_impls {
($type:ty, $date:literal, $time:literal, $off:literal) => {
impl<'a, J> FormattingSpec<$type, J> {
Expand Down

0 comments on commit c68d04d

Please sign in to comment.