Trait block_tools::db::use_diesel::expression_methods::PgTimestampExpressionMethods[][src]

pub trait PgTimestampExpressionMethods: Expression {
    pub fn at_time_zone<T>(
        self,
        timezone: T
    ) -> AtTimeZone<Self, <T as AsExpression<Text>>::Expression>
    where
        T: AsExpression<Text>
, { ... } }

PostgreSQL specific methods present on timestamp expressions.

Provided methods

pub fn at_time_zone<T>(
    self,
    timezone: T
) -> AtTimeZone<Self, <T as AsExpression<Text>>::Expression> where
    T: AsExpression<Text>, 
[src]

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);
Loading content...

Implementors

impl<T> PgTimestampExpressionMethods for T where
    T: Expression,
    <T as Expression>::SqlType: DateTimeLike, 
[src]

Loading content...