Skip to content

Commit

Permalink
Fix issues with from_partial method implementations (#200)
Browse files Browse the repository at this point in the history
See boa-dev/boa#4167 for reference on fixes
  • Loading branch information
nekevss authored Feb 20, 2025
1 parent 28f24a9 commit cba21e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/builtins/core/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl PlainDate {
partial.year.is_some() || (partial.era.is_some() && partial.era_year.is_some());
let month_check = partial.month.is_some() || partial.month_code.is_some();
if !year_check || !month_check || partial.day.is_none() {
return Err(TemporalError::range().with_message("Invalid PlainDate fields provided."));
return Err(TemporalError::r#type().with_message("Invalid PlainDate fields provided."));
}

let overflow = overflow.unwrap_or_default();
Expand Down
7 changes: 5 additions & 2 deletions src/builtins/core/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,12 @@ impl PlainDateTime {
partial: PartialDateTime,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
if partial.date.is_empty() && partial.time.is_empty() {
return Err(TemporalError::r#type().with_message("PartialDateTime cannot be empty."));
}
let date = PlainDate::from_partial(partial.date, overflow)?;
let time = PlainTime::from_partial(partial.time, overflow)?;
Self::from_date_and_time(date, time)
let iso_time = IsoTime::default().with(partial.time, overflow.unwrap_or_default())?;
Self::from_date_and_time(date, PlainTime::new_unchecked(iso_time))
}

/// Creates a new `DateTime` with the fields of a `PartialDateTime`.
Expand Down

0 comments on commit cba21e4

Please sign in to comment.