Skip to content

Commit

Permalink
Adjust docs per feedback and move zoneddatetime_iso
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Feb 11, 2025
1 parent 9ce9250 commit 8b9ec07
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/builtins/compiled/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::{time::EpochNanoseconds, TemporalError, TemporalResult, TimeZone};
impl Now {
/// Returns the current system time as a [`PlainDateTime`] with an optional
/// [`TimeZone`].
///
///
pub fn zoneddatetime_iso(timezone: Option<TimeZone>) -> TemporalResult<ZonedDateTime> {
let timezone =
timezone.unwrap_or(TimeZone::IanaIdentifier(crate::sys::get_system_timezone()?));
Expand All @@ -20,7 +22,7 @@ impl Now {
/// Returns the current system time as a [`PlainDateTime`] with an optional
/// [`TimeZone`].
///
/// Enable with the `compiled_data` feature flag.
/// Enable with the `compiled_data` and `sys` feature flags.
pub fn plain_datetime_iso(timezone: Option<TimeZone>) -> TemporalResult<PlainDateTime> {
let provider = TZ_PROVIDER
.lock()
Expand All @@ -34,7 +36,7 @@ impl Now {
/// Returns the current system time as a [`PlainDate`] with an optional
/// [`TimeZone`].
///
/// Enable with the `compiled_data` feature flag.
/// Enable with the `compiled_data` and `sys` feature flags.
pub fn plain_date_iso(timezone: Option<TimeZone>) -> TemporalResult<PlainDate> {
let provider = TZ_PROVIDER
.lock()
Expand All @@ -48,7 +50,7 @@ impl Now {
/// Returns the current system time as a [`PlainTime`] with an optional
/// [`TimeZone`].
///
/// Enable with the `compiled_data` feature flag.
/// Enable with the `compiled_data` and `sys` feature flags.
pub fn plain_time_iso(timezone: Option<TimeZone>) -> TemporalResult<PlainTime> {
let provider = TZ_PROVIDER
.lock()
Expand Down
24 changes: 18 additions & 6 deletions src/builtins/core/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ use super::{
pub struct Now;

impl Now {
pub fn instant_with_epoch_nanoseconds(epoch_nanoseconds: EpochNanoseconds) -> Instant {
Instant::from(epoch_nanoseconds)
}

/// Returns the current system `DateTime` based off the provided system args
///
/// ## Order of operations
Expand Down Expand Up @@ -71,7 +67,7 @@ impl Now {
epoch_nanos: EpochNanoseconds,
timezone: TimeZone,
) -> TemporalResult<ZonedDateTime> {
let instant = Self::instant_with_epoch_nanoseconds(epoch_nanos);
let instant = Instant::from(epoch_nanos);
Ok(ZonedDateTime::new_unchecked(
instant,
Calendar::default(),
Expand All @@ -83,16 +79,32 @@ impl Now {
#[cfg(feature = "sys")]
impl Now {
/// Returns the current instant
///
/// Enable with the `sys` feature flag.
pub fn instant() -> TemporalResult<Instant> {
let system_nanos = crate::sys::get_system_nanoseconds()?;
let epoch_nanos = EpochNanoseconds::try_from(system_nanos)?;
Ok(Self::instant_with_epoch_nanoseconds(epoch_nanos))
Ok(Instant::from(epoch_nanos))
}

/// Returns the current time zone.
///
/// Enable with the `sys` feature flag.
pub fn time_zone_identifier() -> TemporalResult<String> {
crate::sys::get_system_timezone()
}

/// Returns the current system time as a [`PlainDateTime`] with an optional
/// [`TimeZone`].
///
/// Enable with the `sys` feature flag.
pub fn zoneddatetime_iso(timezone: Option<TimeZone>) -> TemporalResult<ZonedDateTime> {
let timezone =
timezone.unwrap_or(TimeZone::IanaIdentifier(crate::sys::get_system_timezone()?));
let system_nanos = crate::sys::get_system_nanoseconds()?;
let epoch_nanos = EpochNanoseconds::try_from(system_nanos)?;
Now::zoneddatetime_iso_with_system_values(epoch_nanos, timezone)
}
}

impl Now {
Expand Down

0 comments on commit 8b9ec07

Please sign in to comment.