diesel::prelude

Trait PgTimestampExpressionMethods

source
pub trait PgTimestampExpressionMethods: Expression + Sized {
    // Provided method
    fn at_time_zone<T>(self, timezone: T) -> AtTimeZone<Self, T>
       where T: AsExpression<VarChar> { ... }
}
Available on crate feature postgres_backend only.
Expand description

PostgreSQL specific methods present on timestamp expressions.

Provided Methods§

source

fn at_time_zone<T>(self, timezone: T) -> AtTimeZone<Self, T>

Creates a PostgreSQL “AT TIME ZONE” expression.

When this is called on a TIMESTAMP WITHOUT TIME ZONE column, the value will be treated as if were in the given time zone, and then converted to UTC.

When this is called on a TIMESTAMP WITH TIME ZONE column, the value will be converted to the given time zone, and then have its time zone information removed.

§Example
let christmas_morning = NaiveDate::from_ymd(2017, 12, 25)
    .and_hms(8, 0, 0);
diesel::insert_into(timestamps)
    .values(timestamp.eq(christmas_morning))
    .execute(connection)?;

let utc_time = timestamps
    .select(timestamp.at_time_zone("UTC"))
    .first(connection)?;
assert_eq!(christmas_morning, utc_time);

let eastern_time = timestamps
    .select(timestamp.at_time_zone("EST"))
    .first(connection)?;
let five_hours_later = christmas_morning + Duration::hours(5);
assert_eq!(five_hours_later, eastern_time);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Expression> PgTimestampExpressionMethods for T
where T::SqlType: DateTimeLike,