Skip to content

Bump ixdtf and complete changes for update #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ icu_calendar = { version = "2.0.0", default-features = false }
icu_locale = "2.0.0"
rustc-hash = "2.1.0"
num-traits = { version = "0.2.19", default-features = false }
ixdtf = "0.4.0"
ixdtf = "0.5.0"
iana-time-zone = "0.1.63"
log = "0.4.27"
tzif = "0.3.0"
Expand Down
10 changes: 5 additions & 5 deletions src/builtins/core/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ impl Instant {
let ns_offset = match ixdtf_record.offset {
UtcOffsetRecordOrZ::Offset(offset) => {
let ns = offset
.fraction
.fraction()
.and_then(|x| x.to_nanoseconds())
.unwrap_or(0);
(offset.hour as i64 * NANOSECONDS_PER_HOUR
+ i64::from(offset.minute) * NANOSECONDS_PER_MINUTE
+ i64::from(offset.second) * NANOSECONDS_PER_SECOND
(offset.hour() as i64 * NANOSECONDS_PER_HOUR
+ i64::from(offset.minute()) * NANOSECONDS_PER_MINUTE
+ i64::from(offset.second().unwrap_or(0)) * NANOSECONDS_PER_SECOND
+ i64::from(ns))
* offset.sign as i64
* offset.sign() as i64
}
UtcOffsetRecordOrZ::Z => 0,
};
Expand Down
28 changes: 18 additions & 10 deletions src/builtins/core/timezone.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! This module implements the Temporal `TimeZone` and components.

use alloc::string::String;
use alloc::string::{String, ToString};
use alloc::{vec, vec::Vec};

use ixdtf::parsers::records::{TimeZoneRecord, UtcOffsetRecord};
use ixdtf::parsers::records::{MinutePrecisionOffset, TimeZoneRecord, UtcOffsetRecord};
use ixdtf::parsers::TimeZoneParser;
use num_traits::ToPrimitive;

use crate::builtins::core::duration::DateDuration;
use crate::parsers::{
parse_allowed_timezone_formats, parse_identifier, parse_offset, FormattableOffset,
FormattableTime, Precision,
parse_allowed_timezone_formats, parse_identifier, FormattableOffset, FormattableTime, Precision,
};
use crate::provider::{TimeZoneOffset, TimeZoneProvider};
use crate::{
Expand All @@ -28,12 +28,24 @@ const NS_IN_HOUR: i128 = 60 * 60 * 1000 * 1000 * 1000;
pub struct UtcOffset(pub(crate) i16);

impl UtcOffset {
pub(crate) fn from_ixdtf_record(record: UtcOffsetRecord) -> Self {
pub(crate) fn from_ixdtf_record(record: MinutePrecisionOffset) -> Self {
// NOTE: ixdtf parser restricts minute/second to 0..=60
let minutes = i16::from(record.hour) * 60 + record.minute as i16;
Self(minutes * i16::from(record.sign as i8))
}

pub fn from_utf8(source: &[u8]) -> TemporalResult<Self> {
let record = TimeZoneParser::from_utf8(source)
.parse_offset()
.map_err(|e| TemporalError::range().with_message(e.to_string()))?;
match record {
UtcOffsetRecord::MinutePrecision(offset) => Ok(Self::from_ixdtf_record(offset)),
_ => {
Err(TemporalError::range().with_message("offset must be a minute precision offset"))
}
}
}

pub fn to_string(&self) -> TemporalResult<String> {
let sign = if self.0 < 0 {
Sign::Negative
Expand All @@ -60,11 +72,7 @@ impl UtcOffset {
impl core::str::FromStr for UtcOffset {
type Err = TemporalError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut cursor = s.chars().peekable();
match parse_offset(&mut cursor)? {
Some(offset) => Ok(Self(offset)),
None => Err(TemporalError::range().with_message("Invalid offset")),
}
Self::from_utf8(s.as_bytes())
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/builtins/core/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,18 +1190,18 @@ impl ZonedDateTime {
let UtcOffsetRecordOrZ::Offset(offset) = record else {
return (None, true);
};
let hours_in_ns = i64::from(offset.hour) * 3_600_000_000_000_i64;
let minutes_in_ns = i64::from(offset.minute) * 60_000_000_000_i64;
let seconds_in_ns = i64::from(offset.minute) * 1_000_000_000_i64;
let hours_in_ns = i64::from(offset.hour()) * 3_600_000_000_000_i64;
let minutes_in_ns = i64::from(offset.minute()) * 60_000_000_000_i64;
let seconds_in_ns = i64::from(offset.second().unwrap_or(0)) * 1_000_000_000_i64;
let ns = offset
.fraction
.fraction()
.and_then(|x| x.to_nanoseconds())
.unwrap_or(0);

(
Some(
(hours_in_ns + minutes_in_ns + seconds_in_ns + i64::from(ns))
* i64::from(offset.sign as i8),
* i64::from(offset.sign() as i8),
),
false,
)
Expand Down
10 changes: 5 additions & 5 deletions src/options/relative_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ impl RelativeTo {
let UtcOffsetRecordOrZ::Offset(offset) = record else {
return (None, true);
};
let hours_in_ns = i64::from(offset.hour) * 3_600_000_000_000_i64;
let minutes_in_ns = i64::from(offset.minute) * 60_000_000_000_i64;
let seconds_in_ns = i64::from(offset.minute) * 1_000_000_000_i64;
let hours_in_ns = i64::from(offset.hour()) * 3_600_000_000_000_i64;
let minutes_in_ns = i64::from(offset.minute()) * 60_000_000_000_i64;
let seconds_in_ns = i64::from(offset.second().unwrap_or(0)) * 1_000_000_000_i64;
let ns = offset
.fraction
.fraction()
.and_then(|x| x.to_nanoseconds())
.unwrap_or(0);
(
Some(
(hours_in_ns + minutes_in_ns + seconds_in_ns + i64::from(ns))
* i64::from(offset.sign as i8),
* i64::from(offset.sign() as i8),
),
false,
)
Expand Down
2 changes: 1 addition & 1 deletion src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use writeable::{impl_display_with_writeable, LengthHint, Writeable};

mod timezone;

pub(crate) use timezone::{parse_allowed_timezone_formats, parse_identifier, parse_offset};
pub(crate) use timezone::{parse_allowed_timezone_formats, parse_identifier};

// TODO: Move `Writeable` functionality to `ixdtf` crate

Expand Down
12 changes: 10 additions & 2 deletions src/parsers/timezone.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloc::borrow::ToOwned;
use core::{iter::Peekable, str::Chars};
use ixdtf::parsers::{records::UtcOffsetRecordOrZ, IxdtfParser};
use ixdtf::parsers::{
records::{UtcOffsetRecord, UtcOffsetRecordOrZ},
IxdtfParser,
};

use crate::{builtins::timezone::UtcOffset, TemporalError, TemporalResult, TimeZone};

Expand Down Expand Up @@ -37,14 +40,19 @@ pub(crate) fn parse_allowed_timezone_formats(s: &str) -> Option<TimeZone> {
match offset {
UtcOffsetRecordOrZ::Z => return Some(TimeZone::default()),
UtcOffsetRecordOrZ::Offset(offset) => {
return Some(TimeZone::UtcOffset(UtcOffset::from_ixdtf_record(offset)))
let offset = match offset {
UtcOffsetRecord::MinutePrecision(offset) => offset,
_ => return None,
};
return Some(TimeZone::UtcOffset(UtcOffset::from_ixdtf_record(offset)));
}
}
}

None
}

// TODO: Update `ixdtf` to expose parse_time_zone_record
#[inline]
pub(crate) fn parse_identifier(source: &str) -> TemporalResult<TimeZone> {
let mut cursor = source.chars().peekable();
Expand Down