pub struct PgTimeZone { /* private fields */ }Expand description
A time zone as PostgreSQL’s TimeZone setting reads it, equal to another when SHOW timezone
names both alike.
use sql_values::{PgTimeZone, TimeZoneError};
assert_eq!(PgTimeZone::parse("europe/rome").unwrap().name(), "Europe/Rome");
// A number is hours east of UTC, a POSIX specification hours west of it.
assert_eq!(PgTimeZone::parse("+02").unwrap().name(), "<+02>-02");
assert_eq!(PgTimeZone::parse("utc+2").unwrap().name(), "UTC+2");
assert_eq!(PgTimeZone::parse("+168"), Err(TimeZoneError::OffsetOutOfRange));
assert_eq!(PgTimeZone::parse("CEST"), Err(TimeZoneError::InvalidValue));Implementations§
Source§impl PgTimeZone
impl PgTimeZone
Sourcepub fn parse(setting: &str) -> Result<Self, TimeZoneError>
pub fn parse(setting: &str) -> Result<Self, TimeZoneError>
PostgreSQL 18’s check_timezone, reading an interval '...', else a number of hours east of UTC
as C’s strtod reads it, else a name pg_tzset loads, GMT, an IANA name in jiff’s
bundled database or a POSIX specification, refused when its offset at 2000-01-01 has
seconds.
§Errors
The TimeZoneError PostgreSQL raises.
use sql_values::PgTimeZone;
let name = |setting| PgTimeZone::parse(setting).map(|zone| zone.to_string());
assert_eq!(name("2.5").unwrap(), "<+02:30>-02:30");
assert_eq!(name("interval '-01:00'").unwrap(), "<-01>+01");
assert_eq!(name("est5edt").unwrap(), "EST5EDT");
assert_eq!(name("xxx3yyy").unwrap(), "XXX3YYY");Sourcepub fn fixed_offset(&self) -> Option<i32>
pub fn fixed_offset(&self) -> Option<i32>
The zone’s one offset east of UTC in seconds when it never changes, as
pg_get_timezone_offset finds it. A POSIX specification counts hours west of UTC, so
+05:30 is five and a half hours behind it.
use sql_values::PgTimeZone;
let offset = |setting| PgTimeZone::parse(setting).unwrap().fixed_offset();
assert_eq!(offset("UTC"), Some(0));
assert_eq!(offset("Etc/GMT+5"), Some(-18_000));
assert_eq!(offset("+2"), Some(7_200));
assert_eq!(offset("interval '-01:00'"), Some(-3_600));
assert_eq!(offset("+05:30"), Some(-19_800));
// Daylight saving time all year, and a daylight offset equal to the standard one.
assert_eq!(offset("EST5EDT,0/0,J365/26"), Some(-14_400));
assert_eq!(offset("EST5EDT5"), Some(-18_000));
// Daylight saving time that ends at the instant it starts again still has two offsets.
assert_eq!(offset("EST5EDT,0/0,J365/25"), None);
assert_eq!(offset("EST5EDT"), None);
assert_eq!(offset("Europe/Rome"), None);Trait Implementations§
Source§impl Clone for PgTimeZone
impl Clone for PgTimeZone
Source§impl Debug for PgTimeZone
impl Debug for PgTimeZone
Source§impl Display for PgTimeZone
impl Display for PgTimeZone
impl Eq for PgTimeZone
Source§impl Hash for PgTimeZone
impl Hash for PgTimeZone
Auto Trait Implementations§
impl Forget for PgTimeZone
impl Freeze for PgTimeZone
impl RefUnwindSafe for PgTimeZone
impl Send for PgTimeZone
impl Sync for PgTimeZone
impl Unpin for PgTimeZone
impl UnsafeUnpin for PgTimeZone
impl UnwindSafe for PgTimeZone
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more