@@ -2128,6 +2128,7 @@ impl From<NaiveDateTime> for NaiveDate {
21282128
21292129/// Iterator over `NaiveDate` with a step size of one day.
21302130#[ derive( Debug , Copy , Clone , Hash , PartialEq , PartialOrd , Eq , Ord ) ]
2131+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
21312132pub struct NaiveDateDaysIterator {
21322133 value : NaiveDate ,
21332134}
@@ -2164,6 +2165,7 @@ impl FusedIterator for NaiveDateDaysIterator {}
21642165
21652166/// Iterator over `NaiveDate` with a step size of one week.
21662167#[ derive( Debug , Copy , Clone , Hash , PartialEq , PartialOrd , Eq , Ord ) ]
2168+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
21672169pub struct NaiveDateWeeksIterator {
21682170 value : NaiveDate ,
21692171}
@@ -2238,6 +2240,23 @@ impl fmt::Debug for NaiveDate {
22382240 }
22392241}
22402242
2243+ #[ cfg( feature = "defmt" ) ]
2244+ impl defmt:: Format for NaiveDate {
2245+ fn format ( & self , fmt : defmt:: Formatter ) {
2246+ let year = self . year ( ) ;
2247+ let mdf = self . mdf ( ) ;
2248+ if ( 0 ..=9999 ) . contains ( & year) {
2249+ defmt:: write!( fmt, "{:02}{:02}" , year / 100 , year % 100 ) ;
2250+ } else {
2251+ // ISO 8601 requires the explicit sign for out-of-range years
2252+ let sign = [ '+' , '-' ] [ ( year < 0 ) as usize ] ;
2253+ defmt:: write!( fmt, "{}{:05}" , sign, year. abs( ) ) ;
2254+ }
2255+
2256+ defmt:: write!( fmt, "-{:02}-{:02}" , mdf. month( ) , mdf. day( ) ) ;
2257+ }
2258+ }
2259+
22412260/// The `Display` output of the naive date `d` is the same as
22422261/// [`d.format("%Y-%m-%d")`](crate::format::strftime).
22432262///
0 commit comments