Skip to content

Commit cd26d34

Browse files
committed
fix bug
1 parent 5d2af71 commit cd26d34

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/tzdb.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,25 @@ impl Tzif {
208208

209209
pub fn get(&self, epoch_seconds: &Seconds) -> TemporalResult<TimeZoneOffset> {
210210
let db = self.get_data_block2()?;
211+
211212
let result = db.transition_times.binary_search(epoch_seconds);
212213

213214
match result {
214215
Ok(idx) => Ok(get_timezone_offset(db, idx - 1)),
216+
// <https://datatracker.ietf.org/doc/html/rfc8536#section-3.2>
217+
// If there are no transitions, local time for all timestamps is specified by the TZ
218+
// string in the footer if present and nonempty; otherwise, it is
219+
// specified by time type 0.
220+
Err(_) if db.transition_times.is_empty() => {
221+
if let Some(posix_tz_string) = self.posix_tz_string() {
222+
resolve_posix_tz_string_for_epoch_seconds(posix_tz_string, epoch_seconds.0)
223+
} else {
224+
Ok(TimeZoneOffset {
225+
offset: db.local_time_type_records[0].utoff.0,
226+
transition_epoch: None,
227+
})
228+
}
229+
}
215230
Err(idx) if idx == 0 => Ok(get_timezone_offset(db, idx)),
216231
Err(idx) => {
217232
if db.transition_times.len() <= idx {
@@ -308,12 +323,11 @@ impl Tzif {
308323

309324
#[inline]
310325
fn get_timezone_offset(db: &DataBlock, idx: usize) -> TimeZoneOffset {
311-
let transition_epoch = db.transition_times[idx];
312326
// NOTE: Transition type can be empty. If no transition_type exists,
313327
// then use 0 as the default index of local_time_type_records.
314328
let offset = db.local_time_type_records[db.transition_types.get(idx).copied().unwrap_or(0)];
315329
TimeZoneOffset {
316-
transition_epoch: Some(transition_epoch.0),
330+
transition_epoch: db.transition_times.get(idx).map(|s| s.0),
317331
offset: offset.utoff.0,
318332
}
319333
}
@@ -370,7 +384,11 @@ fn resolve_posix_tz_string_for_epoch_seconds(
370384
TransitionDay::NoLeap(day) => i32::from(day) - 1,
371385
TransitionDay::WithLeap(day) => i32::from(day),
372386
TransitionDay::Mwd(_month, _week, _day) => {
373-
return Err(TemporalError::general("unimplemented"));
387+
// TODO: build transition epoch from month, week and day.
388+
return Ok(TimeZoneOffset {
389+
offset: offset.offset,
390+
transition_epoch: None,
391+
});
374392
}
375393
};
376394
let transition_epoch = i64::from(year_epoch) + i64::from(days) * 3600 + transition.time.0;

0 commit comments

Comments
 (0)