diff --git a/src/format/formatting.rs b/src/format/formatting.rs index 1e902ec3fb..cc30128f5c 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -9,7 +9,7 @@ use core::borrow::Borrow; use core::fmt::{self, Display, Write}; use core::marker::PhantomData; -use crate::offset::{FixedOffset, Offset}; +use crate::offset::{FixedOffset, Offset, Utc}; use crate::{DateTime, NaiveDate, NaiveDateTime, NaiveTime}; use crate::{Datelike, ParseError, SecondsFormat, TimeZone, Timelike, Weekday}; @@ -344,6 +344,21 @@ formatting_spec_impls!(NaiveDateTime, true, true, false); formatting_spec_impls!(NaiveDate, true, false, false); formatting_spec_impls!(NaiveTime, false, true, false); +macro_rules! formatting_spec_from_impls { + ($src:ty, $dst:ty) => { + impl From> for FormattingSpec<$dst, I> { + fn from(value: FormattingSpec<$src, I>) -> Self { + Self { items: value.items, date_time_type: PhantomData, locale: value.locale } + } + } + }; +} +formatting_spec_from_impls!(NaiveTime, NaiveDateTime); +formatting_spec_from_impls!(NaiveDate, NaiveDateTime); +formatting_spec_from_impls!(NaiveTime, DateTime); +formatting_spec_from_impls!(NaiveDate, DateTime); +formatting_spec_from_impls!(NaiveDateTime, DateTime); + /// A *temporary* object which can be used as an argument to [`format!`] or others. #[derive(Debug)] pub struct Formatter {