Skip to content

Commit 3e5f101

Browse files
committed
WIP
1 parent d1f05eb commit 3e5f101

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/format/formatting.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ impl<'a, J, Tz: TimeZone> FormattingSpec<DateTime<Tz>, J> {
188188
}
189189
}
190190

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

276+
impl<'a> FormattingSpec<DateTime<FixedOffset>, &'a [Item<'a>]> {
277+
/// Creates a new `FormattingSpec` given a slice of [`Item`]'s.
278+
pub const fn from_slice(items: &'a [Item<'a>]) -> Result<Self, ParseError> {
279+
let locale = locales::default_locale();
280+
let mut i = 0;
281+
while i < items.len() {
282+
if let Err(e) = items[i].check_fields(true, true, true, locale) {
283+
return Err(e);
284+
}
285+
i += 1;
286+
}
287+
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
288+
}
289+
290+
/// Creates a new `FormattingSpec` given a slice of [`Item`]'s and a `locale`.
291+
#[cfg(feature = "unstable-locales")]
292+
pub const fn from_slice_localized(
293+
items: &'a [Item<'a>],
294+
locale: Locale,
295+
) -> Result<Self, ParseError> {
296+
let mut i = 0;
297+
while i < items.len() {
298+
if let Err(e) = items[i].check_fields(true, true, true, locale) {
299+
return Err(e);
300+
}
301+
i += 1;
302+
}
303+
Ok(FormattingSpec { items, date_time_type: PhantomData, locale })
304+
}
305+
}
306+
274307
macro_rules! formatting_spec_impls {
275308
($type:ty, $date:literal, $time:literal, $off:literal) => {
276309
impl<'a, J> FormattingSpec<$type, J> {

0 commit comments

Comments
 (0)