-
Notifications
You must be signed in to change notification settings - Fork 183
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
Update ixdtf
to handle unbound fraction length
#6036
base: main
Are you sure you want to change the base?
Changes from 3 commits
9477c8e
f86c37c
6192c3e
73ea171
f3bfb57
bf313b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ pub enum ParseError { | |
InconsistentTimeZoneOffsets, | ||
/// There was an invalid Offset. | ||
InvalidOffsetError, | ||
/// There was an invalid subsecond fraction. | ||
InvalidFraction, | ||
/// The set of time zone fields was not expected for the given type. | ||
/// For example, if a named time zone was present with offset-only parsing, | ||
/// or an offset was present with named-time-zone-only parsing. | ||
|
@@ -326,11 +328,14 @@ impl<'a> Intermediate<'a> { | |
}; | ||
let time_zone_id = mapper.iana_bytes_to_bcp47(iana_identifier); | ||
let date = Date::<Iso>::try_new_iso(self.date.year, self.date.month, self.date.day)?; | ||
let Some(nanosecond) = self.time.fraction.to_nanoseconds() else { | ||
return Err(ParseError::InvalidFraction); | ||
}; | ||
let time = Time::try_new( | ||
self.time.hour, | ||
self.time.minute, | ||
self.time.second, | ||
self.time.nanosecond, | ||
nanosecond, | ||
)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally there'd only be one code path that parses the IXDTF struct into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated I'm not entirely clear what you had meant by also "for |
||
let offset = match time_zone_id.as_str() { | ||
"utc" | "gmt" => Some(UtcOffset::zero()), | ||
|
@@ -367,11 +372,14 @@ impl<'a> Intermediate<'a> { | |
}, | ||
}; | ||
let date = Date::<Iso>::try_new_iso(self.date.year, self.date.month, self.date.day)?; | ||
let Some(nanosecond) = self.time.fraction.to_nanoseconds() else { | ||
return Err(ParseError::InvalidFraction); | ||
}; | ||
let time = Time::try_new( | ||
self.time.hour, | ||
self.time.minute, | ||
self.time.second, | ||
self.time.nanosecond, | ||
nanosecond, | ||
)?; | ||
Ok(time_zone_id.with_offset(offset).at_time((date, time))) | ||
} | ||
|
@@ -389,11 +397,14 @@ impl<'a> Intermediate<'a> { | |
}; | ||
let time_zone_id = mapper.iana_bytes_to_bcp47(iana_identifier); | ||
let date = Date::try_new_iso(self.date.year, self.date.month, self.date.day)?; | ||
let Some(nanosecond) = self.time.fraction.to_nanoseconds() else { | ||
return Err(ParseError::InvalidFraction); | ||
}; | ||
let time = Time::try_new( | ||
self.time.hour, | ||
self.time.minute, | ||
self.time.second, | ||
self.time.nanosecond, | ||
nanosecond, | ||
)?; | ||
let offset = UtcOffset::try_from_utc_offset_record(offset)?; | ||
let zone_variant = match zone_offset_calculator | ||
|
@@ -792,11 +803,14 @@ impl Time { | |
|
||
fn try_from_ixdtf_record(ixdtf_record: &IxdtfParseRecord) -> Result<Self, ParseError> { | ||
let time_record = ixdtf_record.time.ok_or(ParseError::MissingFields)?; | ||
let Some(nanosecond) = time_record.fraction.to_nanoseconds() else { | ||
return Err(ParseError::InvalidFraction); | ||
}; | ||
let time = Self::try_new( | ||
time_record.hour, | ||
time_record.minute, | ||
time_record.second, | ||
time_record.nanosecond, | ||
nanosecond, | ||
)?; | ||
Ok(time) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -46,6 +46,8 @@ pub enum ParseError { | |||||
TimeSecond, | ||||||
#[displaydoc("Invalid character while parsing fraction part value.")] | ||||||
FractionPart, | ||||||
#[displaydoc("Fraction part value exceeds a representable range.")] | ||||||
InvalidFractionRange, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Invalid" is not very descriptive. This is an error, that already tells me that something is not valid.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was double checking this and the error is specific to a Duration hour fraction and minute fraction potentially exceeding the range of |
||||||
#[displaydoc("Invalid character while parsing date separator.")] | ||||||
DateSeparator, | ||||||
#[displaydoc("Invalid character while parsing time separator.")] | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is overkill. I'd rather document that sub-nanoseconds are truncated. The formatting code only supports nanosecond precision anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, I'd prefer naming this
InvalidFraction
is what I'd expect for a string like "12:48:16.a0", which already producesSyntax
.