Struct GapInfo
pub struct GapInfo {
pub begin: Option<(NaiveDateTime, TzOffset)>,
pub end: Option<DateTime<Tz>>,
}Expand description
Represents the information of a gap.
This returns useful information that can be used when converting a local NaiveDateTime
to a timezone-aware DateTime with chrono::TimeZone::from_local_datetime and a gap
(chrono::LocalResult::None) is found.
§Examples
In the America/New_York timezone the clocks went forward one hour at 2026-03-08T02:00:00.
The local time 2026-03-08T01:30:00 exists, but 2026-03-08T02:30:00 falls in the gap and
does not.
use arrow_array::timezone::{GapInfo, Tz};
use chrono::{DateTime, FixedOffset, LocalResult, NaiveDateTime, Offset, TimeZone};
let tz: Tz = "America/New_York".parse().unwrap();
let expect_offset: FixedOffset = "-0500".parse().unwrap();
// A local time before the gap has a single offset, and is not in a gap.
let exists: NaiveDateTime = "2026-03-08T01:30:00".parse().unwrap();
let offset = tz.offset_from_local_datetime(&exists).single().unwrap();
assert_eq!(offset.fix(), expect_offset);
assert!(GapInfo::new(&exists, &tz).is_none());
// A local time inside the gap has no offset...
let not_exist: NaiveDateTime = "2026-03-08T02:30:00".parse().unwrap();
let offset = tz.offset_from_local_datetime(¬_exist);
assert!(matches!(offset, LocalResult::None));
// ...but `GapInfo` describes the gap it falls in.
let GapInfo { begin, end } = GapInfo::new(¬_exist, &tz).unwrap();
// The gap begins at 02:00 local time. The offset is the one in effect before the gap.
let (begin_datetime, begin_offset) = begin.unwrap();
let expect_begin: NaiveDateTime = "2026-03-08T02:00:00".parse().unwrap();
assert_eq!(begin_datetime, expect_begin);
assert_eq!(begin_offset.fix(), expect_offset);
// The gap ends at 03:00 local time, with the offset in effect after the gap.
let expect_end: DateTime<FixedOffset> = "2026-03-08T03:00:00-0400".parse().unwrap();
assert_eq!(end.unwrap(), expect_end.with_timezone(&tz));Fields§
§begin: Option<(NaiveDateTime, TzOffset)>When available it contains information about the beginning of the gap.
The time represents the first instant in which the gap starts.
This means that it is the first instant that when used with
chrono::TimeZone::from_local_datetime it will return
chrono::LocalResult::None.
The offset represents the offset of the first instant before the gap.
end: Option<DateTime<Tz>>When available it contains the first instant after the gap.
Implementations§
§impl GapInfo
impl GapInfo
pub fn new(local: &NaiveDateTime, tz: &Tz) -> Option<GapInfo>
pub fn new(local: &NaiveDateTime, tz: &Tz) -> Option<GapInfo>
Return information about a gap.
It returns None if local is not in a gap for the current timezone. Timezones
that represent fixed offsets contain no gaps and therefore always return None.
If local is at the limits of the known timestamps the fields begin or end in
GapInfo will be None.