Skip to content
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

Implement Duration::round and some general updates/fixes #24

Merged
merged 8 commits into from
Feb 25, 2024
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
13 changes: 10 additions & 3 deletions src/components/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,19 @@ impl<C: CalendarProtocol> CalendarSlot<C> {
) -> TemporalResult<Date<C>> {
match self {
CalendarSlot::Builtin(AnyCalendar::Iso(_)) => {
// 8. Let norm be NormalizeTimeDuration(duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
// 8. Let norm be NormalizeTimeDuration(duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]],
// duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]]).
// 9. Let balanceResult be BalanceTimeDuration(norm, "day").
let (balance_days, _) = TimeDuration::from_normalized(
duration.time().to_normalized(),
TemporalUnit::Day,
)?;
// 10. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]] + balanceResult.[[Days]], overflow).

// 10. Let result be ? AddISODate(date.[[ISOYear]], date.[[ISOMonth]], date.[[ISODay]], duration.[[Years]],
// duration.[[Months]], duration.[[Weeks]], duration.[[Days]] + balanceResult.[[Days]], overflow).
let result = date.iso.add_iso_date(
&DateDuration::new_unchecked(
duration.days(),
duration.years(),
duration.months(),
duration.weeks(),
duration.days() + balance_days,
Expand Down Expand Up @@ -536,6 +539,10 @@ impl<C: CalendarProtocol> CalendarSlot<C> {
context: &mut C::Context,
) -> TemporalResult<Duration> {
match self {
CalendarSlot::Builtin(AnyCalendar::Iso(_)) => {
let date_duration = one.iso.diff_iso_date(&two.iso, largest_unit)?;
Ok(Duration::from_date_duration(&date_duration))
}
CalendarSlot::Builtin(_) => {
Err(TemporalError::range().with_message("Not yet implemented."))
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ impl<C: CalendarProtocol> Date<C> {
) -> TemporalResult<Self> {
// 1. If options is not present, set options to undefined.
// 2. If duration.[[Years]] ≠ 0, or duration.[[Months]] ≠ 0, or duration.[[Weeks]] ≠ 0, then
if duration.date().years() != 0.0
|| duration.date().months() != 0.0
|| duration.date().weeks() != 0.0
if duration.date().years != 0.0
|| duration.date().months != 0.0
|| duration.date().weeks != 0.0
{
// a. If dateAdd is not present, then
// i. Set dateAdd to unused.
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<C: CalendarProtocol> Date<C> {

if largest_unit == TemporalUnit::Day {
let days = self.days_until(other);
return Ok(Duration::from_date_duration(DateDuration::new(
return Ok(Duration::from_date_duration(&DateDuration::new(
0f64,
0f64,
0f64,
Expand Down
Loading