Skip to content

Commit

Permalink
Work on building out instant methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Jan 7, 2024
1 parent 6c5dfe0 commit 2eea1c9
Show file tree
Hide file tree
Showing 7 changed files with 1,284 additions and 971 deletions.
16 changes: 13 additions & 3 deletions core/temporal/src/components/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::{
};
use std::{any::Any, str::FromStr};

use super::duration::TimeDuration;

/// The native Rust implementation of `Temporal.PlainDate`.
#[derive(Debug, Default, Clone)]
pub struct Date<C: CalendarProtocol> {
Expand Down Expand Up @@ -156,12 +158,20 @@ impl<C: CalendarProtocol> Date<C> {

// 3. Let overflow be ? ToTemporalOverflow(options).
// 4. Let days be ? BalanceTimeDuration(duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "day").[[Days]].
let (days, _) = duration.balance_time_duration(TemporalUnit::Day)?;
let (days, _) = TimeDuration::new_unchecked(
duration.hours(),
duration.minutes(),
duration.seconds(),
duration.milliseconds(),
duration.microseconds(),
duration.nanoseconds(),
)
.balance(duration.days(), TemporalUnit::Day)?;

// 5. Let result be ? AddISODate(plainDate.[[ISOYear]], plainDate.[[ISOMonth]], plainDate.[[ISODay]], 0, 0, 0, days, overflow).
let result = self
.iso
.add_iso_date(&DateDuration::new(0f64, 0f64, 0f64, days), overflow)?;
.add_iso_date(&DateDuration::new(0f64, 0f64, 0f64, days)?, overflow)?;

Ok(Self::new_unchecked(result, self.calendar().clone()))
}
Expand Down Expand Up @@ -202,7 +212,7 @@ impl<C: CalendarProtocol> Date<C> {
0f64,
0f64,
f64::from(days),
)));
)?));
}

self.calendar()
Expand Down
Loading

0 comments on commit 2eea1c9

Please sign in to comment.