Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf00d208

Browse files
committed
Update impl for Timestamp
The impl now directly computes `Timestamp` rather than going through`DateTime` and `Zoned`.
1 parentdf2f37d commitf00d208

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

‎postgres-types/src/jiff_01.rs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ const fn base() -> DateTime {
1313
DateTime::constant(2000,1,1,0,0,0,0)
1414
}
1515

16+
/// The number of seconds from 2000-01-01 00:00:00 UTC to the Unix epoch.
17+
constY2K_EPOCH:i64 =946684800;
18+
19+
fnbase_ts() ->Timestamp{
20+
Timestamp::new(Y2K_EPOCH,0).unwrap()
21+
}
22+
1623
impl<'a>FromSql<'a>forDateTime{
1724
fnfrom_sql(_:&Type,raw:&[u8]) ->Result<DateTime,Box<dynError +Sync +Send>>{
1825
let t = types::timestamp_from_sql(raw)?;
@@ -33,22 +40,17 @@ impl ToSql for DateTime {
3340
}
3441

3542
impl<'a>FromSql<'a>forTimestamp{
36-
fnfrom_sql(type_:&Type,raw:&[u8]) ->Result<Timestamp,Box<dynError +Sync +Send>>{
37-
Ok(DateTime::from_sql(type_, raw)?
38-
.to_zoned(TimeZone::UTC)?
39-
.timestamp())
43+
fnfrom_sql(_:&Type,raw:&[u8]) ->Result<Timestamp,Box<dynError +Sync +Send>>{
44+
let t = types::timestamp_from_sql(raw)?;
45+
Ok(base_ts().checked_add(Span::new().microseconds(t))?)
4046
}
4147

4248
accepts!(TIMESTAMPTZ);
4349
}
4450

4551
implToSqlforTimestamp{
4652
fnto_sql(&self, _:&Type,w:&mutBytesMut) ->Result<IsNull,Box<dynError +Sync +Send>>{
47-
types::timestamp_to_sql(
48-
self.since(base().to_zoned(TimeZone::UTC)?)?
49-
.get_microseconds(),
50-
w,
51-
);
53+
types::timestamp_to_sql(self.since(base_ts())?.get_microseconds(), w);
5254
Ok(IsNull::No)
5355
}
5456

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp