Skip to content

Commit

Permalink
Fix time zone parsing issue/test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Oct 5, 2023
1 parent 6eb3b15 commit 9db8b47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 8 additions & 2 deletions boa_parser/src/temporal/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ pub(crate) fn parse_annotated_date_time(
tz = annotated_tz.tz;
}

let tz = if tz.name.is_some() || tz.offset.is_some() {
Some(tz)
} else {
None
};

Ok(IsoParseRecord {
date: date_time.date,
time: date_time.time,
tz: Some(tz),
tz,
calendar: annotation_set.calendar,
})
}
Expand Down Expand Up @@ -113,7 +119,7 @@ fn parse_date_time(
} else {
if utc_required {
return Err(Error::general(
"DateTimeUtcOffset is required.",
"DateTimeUTCOffset is required.",
Position::new(1, cursor.pos() + 1),
));
}
Expand Down
17 changes: 5 additions & 12 deletions boa_parser/src/temporal/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,8 @@ fn temporal_date_time_max() {

let tz = &result.tz.unwrap();

let offset_results = &tz.offset.unwrap();

assert_eq!(offset_results.sign, -1);
assert_eq!(offset_results.hour, 3);
assert_eq!(offset_results.minute, 0);
assert_eq!(
offset_results
.second
.mul_add(f64::from(1_000_000), 0.0)
.trunc() as i64,
0.123_456_789_f64.mul_add(1_000_000_f64, 0.0).trunc() as i64
);
// OffsetSubMinute is Empty when TimeZoneIdentifier is present.
assert!(&tz.offset.is_none());

let tz_name = &tz.name.clone().unwrap();

Expand Down Expand Up @@ -87,6 +77,9 @@ fn temporal_annotated_date_time() {

let omit_result = TemporalDateTimeString::parse(false, &mut IsoCursor::new(omitted)).unwrap();

println!("omit result is:");
println!("{omit_result:?\n\n}");

assert!(&omit_result.tz.is_none());

assert_eq!(&omit_result.calendar, &Some("iso8601".to_string()));
Expand Down

0 comments on commit 9db8b47

Please sign in to comment.