Skip to content
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: 13 additions & 0 deletions src/builtins/core/plain_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
},
parsers::IxdtfStringBuilder,
provider::{NeverProvider, TimeZoneProvider},
unix_time::EpochNanoseconds,
MonthCode, TemporalError, TemporalResult, TimeZone,
};
use alloc::string::String;
Expand Down Expand Up @@ -685,6 +686,18 @@ impl PlainDate {
epoch_ns.offset,
)
}

/// Gets the EpochNanoseconds represented by this PlainDate
/// (using noon time, and UTC timezone)
///
// Useful for implementing HandleDateTimeTemporalYearMonth
pub fn epoch_ns_for_utc(&self) -> EpochNanoseconds {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalYearMonth.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon());
debug_assert!(iso.is_ok());
// 3. Let epochNs be ? GetUTCEpochNanoseconds(isoDateTime).
iso.unwrap_or_default().as_nanoseconds()
}
}

// ==== Trait impls ====
Expand Down
10 changes: 10 additions & 0 deletions src/builtins/core/plain_date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
parsers::IxdtfStringBuilder,
primitive::FiniteF64,
provider::{NeverProvider, TimeZoneProvider},
unix_time::EpochNanoseconds,
MonthCode, TemporalError, TemporalResult, TimeZone,
};
use alloc::string::String;
Expand Down Expand Up @@ -907,6 +908,15 @@ impl PlainDateTime {
))
}

/// Gets the EpochNanoseconds represented by this PlainDateTime
/// (using and UTC timezone)
///
// Useful for implementing HandleDateTimeTemporalDateTime
pub fn epoch_ns_for_utc(&self) -> EpochNanoseconds {
// 3. Let epochNs be ? GetUTCEpochNanoseconds(isoDateTime).
self.iso.as_nanoseconds()
}

/// Create a [`PlainDate`] from the current `PlainDateTime`.
#[inline]
pub fn to_plain_date(&self) -> PlainDate {
Expand Down
12 changes: 12 additions & 0 deletions src/builtins/core/plain_month_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ impl PlainMonthDay {
.ns)
}

/// Gets the EpochNanoseconds represented by this MonthDay
/// (using the reference year, noon time, and UTC timezone)
///
// Useful for implementing HandleDateTimeTemporalYearMonth
pub fn epoch_ns_for_utc(&self) -> EpochNanoseconds {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalMonthDay.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon());
debug_assert!(iso.is_ok());
// 3. Let epochNs be ? GetUTCEpochNanoseconds(isoDateTime).
iso.unwrap_or_default().as_nanoseconds()
}

/// Creates a RFC9557 IXDTF string from the current `PlainMonthDay`.
pub fn to_ixdtf_string(&self, display_calendar: DisplayCalendar) -> String {
self.to_ixdtf_writeable(display_calendar)
Expand Down
15 changes: 15 additions & 0 deletions src/builtins/core/plain_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use crate::{
},
error::ErrorMessage,
iso::IsoTime,
iso::{IsoDate, IsoDateTime},
options::{
DifferenceOperation, DifferenceSettings, Overflow, ResolvedRoundingOptions,
RoundingOptions, ToStringRoundingOptions, Unit, UnitGroup,
},
parsers::{parse_time, IxdtfStringBuilder},
unix_time::EpochNanoseconds,
TemporalError, TemporalResult,
};
use alloc::string::String;
Expand Down Expand Up @@ -541,6 +543,19 @@ impl PlainTime {
let builder = IxdtfStringBuilder::default().with_time(result, resolved.precision);
Ok(builder)
}

/// Gets the EpochNanoseconds represented by this PlainTime
/// (using the Unix epoch, and UTC timezone)
///
// Useful for implementing HandleDateTimeTemporalTime
pub fn epoch_ns_for_utc(&self) -> EpochNanoseconds {
// 1. Let isoDate be CreateISODateRecord(1970, 1, 1).
// 2. Let isoDateTime be CombineISODateAndTimeRecord(isoDate, temporalTime.[[Time]]).
let iso = IsoDateTime::new(IsoDate::UNIX_EPOCH, self.iso);
debug_assert!(iso.is_ok());
// 3. Let epochNs be ? GetUTCEpochNanoseconds(isoDateTime).
iso.unwrap_or_default().as_nanoseconds()
}
}

impl From<PlainDateTime> for PlainTime {
Expand Down
16 changes: 13 additions & 3 deletions src/builtins/core/plain_year_month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ impl PlainYearMonth {
}

/// Gets the epochMilliseconds represented by this YearMonth in the given timezone
/// (using the reference year, and noon time)
///
// Useful for implementing HandleDateTimeTemporalYearMonth
/// (using the reference day, and noon time)
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
Expand All @@ -614,6 +612,18 @@ impl PlainYearMonth {
.ns)
}

/// Gets the EpochNanoseconds represented by this YearMonth
/// (using the reference day, noon time, and UTC timezone)
///
// Useful for implementing HandleDateTimeTemporalYearMonth
pub fn epoch_ns_for_utc(&self) -> EpochNanoseconds {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalYearMonth.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon());
debug_assert!(iso.is_ok());
// 3. Let epochNs be ? GetUTCEpochNanoseconds(isoDateTime).
iso.unwrap_or_default().as_nanoseconds()
}

/// Returns a RFC9557 IXDTF string for the current `PlainYearMonth`
#[inline]
pub fn to_ixdtf_string(&self, display_calendar: DisplayCalendar) -> String {
Expand Down
2 changes: 2 additions & 0 deletions src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ pub struct IsoDate {
}

impl IsoDate {
pub(crate) const UNIX_EPOCH: Self = Self::new_unchecked(1970, 1, 1);

/// Creates a new `IsoDate` without determining the validity.
pub(crate) const fn new_unchecked(year: i32, month: u8, day: u8) -> Self {
Self { year, month, day }
Expand Down
3 changes: 3 additions & 0 deletions temporal_capi/bindings/c/PlainDate.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions temporal_capi/bindings/c/PlainDateTime.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions temporal_capi/bindings/c/PlainMonthDay.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions temporal_capi/bindings/c/PlainTime.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions temporal_capi/bindings/c/PlainYearMonth.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainDate.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainDate.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainDateTime.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainDateTime.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainMonthDay.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading