Skip to main content

PgTimeZone

Struct PgTimeZone 

Source
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::postgres::{PgTimeZone, TimeZoneError};

#[cfg(feature = "tzdb")]
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

Source

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::postgres::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");
Source

pub fn name(&self) -> &str

The name SHOW timezone prints for the zone.

Source

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::postgres::PgTimeZone;

let offset = |setting| PgTimeZone::parse(setting).unwrap().fixed_offset();
#[cfg(feature = "tzdb")]
{
    assert_eq!(offset("UTC"), Some(0));
    assert_eq!(offset("Etc/GMT+5"), Some(-18_000));
    assert_eq!(offset("Europe/Rome"), None);
}
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);

Trait Implementations§

Source§

impl Clone for PgTimeZone

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgTimeZone

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PgTimeZone

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PgTimeZone

Source§

impl Hash for PgTimeZone

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PgTimeZone

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Forget for PgTimeZone

§

impl Freeze for PgTimeZone

§

impl Move for PgTimeZone

§

impl RefUnwindSafe for PgTimeZone

§

impl Send for PgTimeZone
where RawVecInner: Send, Repr: Send,

§

impl Sync for PgTimeZone
where RawVecInner: Sync, Repr: Sync,

§

impl Unpin for PgTimeZone
where *const u8 is !null: Unpin, *const u8: Unpin,

§

impl UnsafeUnpin for PgTimeZone

§

impl UnwindSafe for PgTimeZone
where RawVecInner: UnwindSafe, *const u8: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.