Struct TimeZonePrecedingTransitions
pub struct TimeZonePrecedingTransitions<'t> { /* private fields */ }
An iterator over time zone transitions going backward in time.
This iterator is created by TimeZone::preceding.
Example: show the 5 previous time zone transitions
This shows how to find the 5 preceding time zone transitions (from a particular datetime) for a particular time zone:
use jiff::{tz::offset, ZonedDateTime};
let now: ZonedDateTime = "2024-12-31 18:25-05[America/New_York]".parse()?;
let transitions = now
.time_zone()
.preceding(now.timestamp())
.take(5)
.map(|t| (
t.timestamp().to_zoned_datetime(now.time_zone().clone()),
t.offset(),
t.abbreviation().to_string(),
))
.collect::<Vec<_>>();
assert_eq!(transitions, vec![
(
"2024-11-03 01:00-05[America/New_York]".parse()?,
offset(-5),
"EST".to_string(),
),
(
"2024-03-10 03:00-04[America/New_York]".parse()?,
offset(-4),
"EDT".to_string(),
),
(
"2023-11-05 01:00-05[America/New_York]".parse()?,
offset(-5),
"EST".to_string(),
),
(
"2023-03-12 03:00-04[America/New_York]".parse()?,
offset(-4),
"EDT".to_string(),
),
(
"2022-11-06 01:00-05[America/New_York]".parse()?,
offset(-5),
"EST".to_string(),
),
]);
# Ok::<(), Box<dyn std::error::Error>>(())
Trait Implementations
impl<'t> Clone for TimeZonePrecedingTransitions<'t>
fn clone(&self) -> Self
impl<'t> Debug for TimeZonePrecedingTransitions<'t>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<'t> FusedIterator for TimeZonePrecedingTransitions<'t>
impl<'t> Iterator for TimeZonePrecedingTransitions<'t>
type Item = TimeZoneTransition<'t>;fn next(&mut self) -> Option<TimeZoneTransition<'t>>