Skip to content

Commit eef688a

Browse files
authored
Review Instant API + Duration (#573)
Reviewed both Instant and Duration while working on this, and they appear to be generally fine. Made some updates to Instant, but none really seemed to be needed for Duration.
1 parent e28b788 commit eef688a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/builtins/core/instant.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl From<EpochNanoseconds> for Instant {
157157
// ==== Private API ====
158158

159159
impl Instant {
160-
// TODO: Update to `i128`?
161160
/// Adds a `TimeDuration` to the current `Instant`.
162161
///
163162
/// Temporal-Proposal equivalent: `AddInstant`.
@@ -272,7 +271,7 @@ impl Instant {
272271

273272
// Utility for converting `Instant` to `i128`.
274273
pub fn as_i128(&self) -> i128 {
275-
self.0 .0
274+
self.epoch_nanoseconds().0
276275
}
277276
}
278277

@@ -369,6 +368,7 @@ impl Instant {
369368
}
370369

371370
/// Returns an `Instant` by rounding the current `Instant` according to the provided settings.
371+
#[inline]
372372
pub fn round(&self, options: RoundingOptions) -> TemporalResult<Self> {
373373
let resolved_options = ResolvedRoundingOptions::from_instant_options(options)?;
374374

@@ -377,17 +377,21 @@ impl Instant {
377377
}
378378

379379
/// Returns the `epochMilliseconds` value for this `Instant`.
380+
#[inline]
380381
#[must_use]
381382
pub fn epoch_milliseconds(&self) -> i64 {
382383
self.as_i128().div_euclid(1_000_000) as i64
383384
}
384385

385-
/// Returns the `epochNanoseconds` value for this `Instant`.
386+
/// Returns the [`EpochNanoseconds`] value for this `Instant`.
387+
#[inline]
386388
#[must_use]
387389
pub fn epoch_nanoseconds(&self) -> &EpochNanoseconds {
388390
&self.0
389391
}
390392

393+
/// Returns a [`ZonedDateTime`] for the current `Instant`.
394+
#[inline]
391395
pub fn to_zoned_date_time_iso_with_provider(
392396
&self,
393397
time_zone: TimeZone,
@@ -400,6 +404,7 @@ impl Instant {
400404
// ==== Instant Provider API ====
401405

402406
impl Instant {
407+
/// Returns an RFC9557 IXDTF string representing the current `Instant`.
403408
pub fn to_ixdtf_string_with_provider(
404409
&self,
405410
timezone: Option<TimeZone>,
@@ -410,6 +415,7 @@ impl Instant {
410415
.map(|x| x.write_to_string().into())
411416
}
412417

418+
/// Returns a [`Writeable`] for formatting the current `Instant` in RFC9557's IXDTF.
413419
pub fn to_ixdtf_writeable_with_provider(
414420
&self,
415421
timezone: Option<TimeZone>,

0 commit comments

Comments
 (0)