pub trait PgTimestampExpressionMethods: Sized + Expression {
// Provided method
fn at_time_zone<T>(
self,
timezone: T,
) -> Grouped<AtTimeZone<Self, <T as AsExpression<Text>>::Expression>>
where T: AsExpression<Text> { ... }
}
Expand description
PostgreSQL specific methods present on timestamp expressions.
Provided Methods§
Sourcefn at_time_zone<T>(
self,
timezone: T,
) -> Grouped<AtTimeZone<Self, <T as AsExpression<Text>>::Expression>>where
T: AsExpression<Text>,
fn at_time_zone<T>(
self,
timezone: T,
) -> Grouped<AtTimeZone<Self, <T as AsExpression<Text>>::Expression>>where
T: AsExpression<Text>,
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);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.