Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jul 27, 2023
1 parent d220817 commit 39d6449
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 @@ -188,7 +188,9 @@ impl<'a, J, Tz: TimeZone> FormattingSpec<DateTime<Tz>, J> {
}
}

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 @@ -271,6 +273,37 @@ impl<'a, Tz: TimeZone> FormattingSpec<DateTime<Tz>, &'a [Item<'a>]> {
}
}

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;
}
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
}

/// 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;
}
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
}
}

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 39d6449

Please sign in to comment.