Trait diesel::expression_methods::PgTimestampExpressionMethods[][src]

pub trait PgTimestampExpressionMethods: Expression + Sized {
    fn at_time_zone<T>(self, timezone: T) -> AtTimeZone<Self, T::Expression>
    where
        T: AsExpression<VarChar>
, { ... } }
Expand description

PostgreSQL specific methods present on timestamp expressions.

Provided methods

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);

Implementors