From 9baaaa4de5e490c34b3d7a10301fbbc0cfecdf4a Mon Sep 17 00:00:00 2001
From: Kevin Ness <46825870+nekevss@users.noreply.github.com>
Date: Wed, 27 Nov 2024 23:22:02 -0600
Subject: [PATCH] Add accessor methods to ZonedDateTime + organization
---
src/components/duration/normalized.rs | 2 +-
src/components/zoneddatetime.rs | 234 +++++++++++++++++++++++++-
2 files changed, 229 insertions(+), 7 deletions(-)
diff --git a/src/components/duration/normalized.rs b/src/components/duration/normalized.rs
index 1d4d7ebb..0b6799d5 100644
--- a/src/components/duration/normalized.rs
+++ b/src/components/duration/normalized.rs
@@ -74,7 +74,7 @@ impl NormalizedTimeDuration {
// TODO: Potentially, update divisor to u64?
/// `Divide the NormalizedTimeDuraiton` by a divisor.
- pub(super) fn divide(&self, divisor: i64) -> i128 {
+ pub(crate) fn divide(&self, divisor: i64) -> i128 {
// TODO: Validate.
self.0 / i128::from(divisor)
}
diff --git a/src/components/zoneddatetime.rs b/src/components/zoneddatetime.rs
index f6feed4d..ac78dde8 100644
--- a/src/components/zoneddatetime.rs
+++ b/src/components/zoneddatetime.rs
@@ -3,8 +3,8 @@
use tinystr::TinyAsciiStr;
use crate::{
- components::{calendar::Calendar, tz::TimeZone, Instant},
- iso::IsoDateTime,
+ components::{calendar::Calendar, duration::normalized::NormalizedTimeDuration, tz::TimeZone, Instant},
+ iso::{IsoDate, IsoDateTime},
options::{ArithmeticOverflow, Disambiguation},
Sign, TemporalError, TemporalResult,
};
@@ -78,7 +78,7 @@ impl ZonedDateTime {
.with_message("Intermediate ISO datetime was not within a valid range."));
}
// 6. Let intermediateNs be ! GetEpochNanosecondsFor(timeZone, intermediateDateTime, compatible).
- let intermediate_ns = self.tz().get_epoch_nanoseconds_for(
+ let intermediate_ns = self.timezone().get_epoch_nanoseconds_for(
intermediate,
Disambiguation::Compatible,
provider,
@@ -113,7 +113,7 @@ impl ZonedDateTime {
.add_as_instant(duration, overflow, provider)?
.epoch_nanos;
// 9. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
- Self::try_new(epoch_ns, self.calendar().clone(), self.tz().clone())
+ Self::try_new(epoch_ns, self.calendar().clone(), self.timezone().clone())
}
}
@@ -137,7 +137,7 @@ impl ZonedDateTime {
/// Returns `ZonedDateTime`'s `TimeZone` slot.
#[inline]
#[must_use]
- pub fn tz(&self) -> &TimeZone {
+ pub fn timezone(&self) -> &TimeZone {
&self.tz
}
@@ -166,7 +166,7 @@ impl ZonedDateTime {
}
}
-// ===== TzProvider APIs for ZonedDateTime =====
+// ===== Experimental TZ_PROVIDER accessor implementations =====
#[cfg(feature = "experimental")]
impl ZonedDateTime {
@@ -240,7 +240,103 @@ impl ZonedDateTime {
self.millisecond_with_provider(provider.deref())
}
+}
+
+// ==== Experimental TZ_PROVIDER calendar method implementations ====
+
+#[cfg(feature = "experimental")]
+impl ZonedDateTime {
+ pub fn era(&self) -> TemporalResult