Skip to content
Closed
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
18 changes: 18 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,23 @@ impl PlainDate {
epoch_ns.offset,
)
}

/// Gets the epochMilliseconds represented by this PlainDate in the given timezone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Gets the epochMilliseconds represented by this PlainDate in the given timezone
/// Gets the EpochNanoseconds represented by this PlainDate in the given timezone

Also applies to the rest of the new methods

/// (at noon time)
///
// Useful for implementing HandleDateTimeTemporalDate
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanoseconds> {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalDate.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(self.iso, IsoTime::noon())?;
// 3. Let epochNs be ? GetEpochNanosecondsFor(dateTimeFormat.[[TimeZone]], isoDateTime, compatible).
Ok(time_zone
.get_epoch_nanoseconds_for(iso, Disambiguation::Compatible, provider)?
.ns)
}
}

// ==== Trait impls ====
Expand Down
16 changes: 16 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,21 @@ impl PlainDateTime {
))
}

/// Gets the epochMilliseconds represented by this PlainDateTime in the given timezone
///
// Useful for implementing HandleDateTimeTemporalDateTime
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanoseconds> {
// Let epochNs be ? GetEpochNanosecondsFor(dateTimeFormat.[[TimeZone]],
// isoDateTime, compatible).
Ok(time_zone
.get_epoch_nanoseconds_for(self.iso, Disambiguation::Compatible, provider)?
.ns)
}

/// Create a [`PlainDate`] from the current `PlainDateTime`.
#[inline]
pub fn to_plain_date(&self) -> PlainDate {
Expand Down
23 changes: 21 additions & 2 deletions src/builtins/core/plain_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ use crate::{
},
error::ErrorMessage,
iso::IsoTime,
iso::{IsoDate, IsoDateTime},
options::{
DifferenceOperation, DifferenceSettings, Overflow, ResolvedRoundingOptions,
DifferenceOperation, DifferenceSettings, Disambiguation, Overflow, ResolvedRoundingOptions,
RoundingOptions, ToStringRoundingOptions, Unit, UnitGroup,
},
parsers::{parse_time, IxdtfStringBuilder},
TemporalError, TemporalResult,
provider::TimeZoneProvider,
unix_time::EpochNanoseconds,
TemporalError, TemporalResult, TimeZone,
};
use alloc::string::String;
use core::str::FromStr;
Expand Down Expand Up @@ -541,6 +544,22 @@ impl PlainTime {
let builder = IxdtfStringBuilder::default().with_time(result, resolved.precision);
Ok(builder)
}
/// Gets the epochMilliseconds represented by this PlainTime in the given timezone
/// (on Jan 1 1970)
///
// Useful for implementing HandleDateTimeTemporalTime
pub fn epoch_ns_for_with_provider(
&self,
time_zone: TimeZone,
provider: &(impl TimeZoneProvider + ?Sized),
) -> TemporalResult<EpochNanoseconds> {
// 2. Let isoDateTime be CombineISODateAndTimeRecord(temporalDate.[[ISODate]], NoonTimeRecord()).
let iso = IsoDateTime::new(IsoDate::UNIX_EPOCH, self.iso)?;
// 3. Let epochNs be ? GetEpochNanosecondsFor(dateTimeFormat.[[TimeZone]], isoDateTime, compatible).
Ok(time_zone
.get_epoch_nanoseconds_for(iso, Disambiguation::Compatible, provider)?
.ns)
}
}

impl From<PlainDateTime> for PlainTime {
Expand Down
1 change: 1 addition & 0 deletions src/iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ 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
6 changes: 6 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.

6 changes: 6 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.

6 changes: 6 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.

4 changes: 4 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.

19 changes: 19 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.

4 changes: 4 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.

19 changes: 19 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.

4 changes: 4 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/PlainTime.d.hpp

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

Loading