Skip to content

Commit a4e2983

Browse files
committed
Add CFTimeZone::name
Add a `name` method to `CFTimeZone` to get the time zone ID (e.g., "America/Los_Angeles") of the current time zone. Core Foundation calls this "name" instead of "id" in its method signatures, but acknowledges it in the closely-related NSTimeZone related docs. Since most of the other methods in this library match closely with CF naming, also use `name` here. > Time zone database entries such as “America/Los_Angeles” are IDs, not > names. An example of a time zone name is “Pacific Daylight Time”. > Although many NSTimeZone symbols include the word “name”, they > actually refer to IDs.
1 parent 749c085 commit a4e2983

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core-foundation-sys/src/timezone.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::os::raw::c_void;
1111

1212
use base::{CFAllocatorRef, CFTypeID};
1313
use date::{CFTimeInterval, CFAbsoluteTime};
14+
use string::CFStringRef;
1415

1516
#[repr(C)]
1617
pub struct __CFTimeZone(c_void);
@@ -24,4 +25,5 @@ extern {
2425
pub fn CFTimeZoneGetSecondsFromGMT(tz: CFTimeZoneRef, time: CFAbsoluteTime) -> CFTimeInterval;
2526

2627
pub fn CFTimeZoneGetTypeID() -> CFTypeID;
28+
pub fn CFTimeZoneGetName(tz: CFTimeZoneRef) -> CFStringRef;
2729
}

core-foundation/src/timezone.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use core_foundation_sys::base::kCFAllocatorDefault;
1414

1515
use base::TCFType;
1616
use date::{CFDate, CFTimeInterval};
17+
use string::CFString;
1718

1819
#[cfg(feature = "with-chrono")]
1920
use chrono::{FixedOffset, NaiveDateTime};
@@ -68,6 +69,14 @@ impl CFTimeZone {
6869
pub fn from_offset(offset: FixedOffset) -> CFTimeZone {
6970
CFTimeZone::new(offset.local_minus_utc() as f64)
7071
}
72+
73+
/// The timezone database ID that identifies the time zone. E.g. "America/Los_Angeles" or
74+
/// "Europe/Paris".
75+
pub fn name(&self) -> CFString {
76+
unsafe {
77+
CFString::wrap_under_get_rule(CFTimeZoneGetName(self.0))
78+
}
79+
}
7180
}
7281

7382
#[cfg(test)]

0 commit comments

Comments
 (0)