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
2 changes: 1 addition & 1 deletion src/builtins/core/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const NANOSECONDS_PER_HOUR: i64 = 60 * NANOSECONDS_PER_MINUTE;
///
/// // Convert to a zoned date-time for display in local time
/// let zdt = instant.to_zoned_date_time_iso(timezone);
/// assert_eq!(zdt.timezone().identifier().unwrap(), "America/New_York");
/// assert_eq!(zdt.timezone().identifier(), "America/New_York");
/// assert_eq!(zdt.calendar().identifier(), "iso8601");
/// ```
///
Expand Down
17 changes: 9 additions & 8 deletions src/builtins/core/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ impl UtcOffset {
}
}

pub fn to_string(&self) -> TemporalResult<String> {
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
let sign = if self.0 < 0 {
Sign::Negative
} else {
Expand All @@ -69,7 +70,7 @@ impl UtcOffset {
include_sep: true,
},
};
Ok(formattable_offset.to_string())
formattable_offset.to_string()
}
}

Expand Down Expand Up @@ -138,9 +139,9 @@ impl TimeZone {
}

/// Returns the current `TimeZoneSlot`'s identifier.
pub fn identifier(&self) -> TemporalResult<String> {
pub fn identifier(&self) -> String {
match self {
TimeZone::IanaIdentifier(s) => Ok(s.clone()),
TimeZone::IanaIdentifier(s) => s.clone(),
TimeZone::UtcOffset(offset) => offset.to_string(),
}
}
Expand Down Expand Up @@ -468,18 +469,18 @@ mod tests {
fn from_and_to_string() {
let src = "+09:30";
let tz = TimeZone::try_from_identifier_str(src).unwrap();
assert_eq!(tz.identifier().unwrap(), src);
assert_eq!(tz.identifier(), src);

let src = "-09:30";
let tz = TimeZone::try_from_identifier_str(src).unwrap();
assert_eq!(tz.identifier().unwrap(), src);
assert_eq!(tz.identifier(), src);

let src = "-12:30";
let tz = TimeZone::try_from_identifier_str(src).unwrap();
assert_eq!(tz.identifier().unwrap(), src);
assert_eq!(tz.identifier(), src);

let src = "America/New_York";
let tz = TimeZone::try_from_identifier_str(src).unwrap();
assert_eq!(tz.identifier().unwrap(), src);
assert_eq!(tz.identifier(), src);
}
}
6 changes: 3 additions & 3 deletions src/builtins/core/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl PartialZonedDateTime {
///
/// assert_eq!(zdt.epoch_milliseconds(), 0);
/// assert_eq!(zdt.epoch_nanoseconds().as_i128(), 0);
/// assert_eq!(zdt.timezone().identifier().unwrap(), "UTC");
/// assert_eq!(zdt.timezone().identifier(), "UTC");
/// assert_eq!(zdt.calendar().identifier(), "iso8601");
/// ```
///
Expand Down Expand Up @@ -193,7 +193,7 @@ impl PartialZonedDateTime {
/// ).unwrap();
///
/// // Now we have an exact moment in time in the LA timezone
/// assert_eq!(zdt.timezone().identifier().unwrap(), "America/Los_Angeles");
/// assert_eq!(zdt.timezone().identifier(), "America/Los_Angeles");
/// ```
///
/// ### String formatting (requires provider)
Expand Down Expand Up @@ -1261,7 +1261,7 @@ impl ZonedDateTime {
let offset = self.tz.get_offset_nanos_for(result, provider)?;
let datetime = self.tz.get_iso_datetime_for(&rounded_instant, provider)?;
let (sign, hour, minute) = nanoseconds_to_formattable_offset_minutes(offset)?;
let timezone_id = self.timezone().identifier()?;
let timezone_id = self.timezone().identifier();

let ixdtf_string = IxdtfStringBuilder::default()
.with_date(datetime.date)
Expand Down
3 changes: 1 addition & 2 deletions temporal_capi/bindings/c/TimeZone.h

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

4 changes: 2 additions & 2 deletions temporal_capi/bindings/cpp/temporal_rs/TimeZone.d.hpp

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

14 changes: 6 additions & 8 deletions temporal_capi/bindings/cpp/temporal_rs/TimeZone.hpp

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

6 changes: 2 additions & 4 deletions temporal_capi/src/time_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ pub mod ffi {
.map_err(Into::into)
}

pub fn identifier(&self, write: &mut DiplomatWrite) -> Result<(), TemporalError> {
pub fn identifier(&self, write: &mut DiplomatWrite) {
// TODO ideally this would use Writeable instead of allocating
let s = self.0.identifier()?;
let s = self.0.identifier();

// This can only fail in cases where the DiplomatWriteable is capped, we
// don't care about that.
let _ = write.write_str(&s);

Ok(())
}

#[allow(clippy::should_implement_trait)]
Expand Down