Skip to content

Commit

Permalink
Merge pull request #25 from HRKings/timestamp_conversion
Browse files Browse the repository at this point in the history
Use the appropriate method for unix timestamp conversion
  • Loading branch information
pksunkara authored Oct 6, 2023
2 parents f84954c + 414cab8 commit 277f114
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ fn ulid_to_uuid(input: ulid) -> Uuid {

#[pg_extern(immutable, parallel_safe)]
fn ulid_to_timestamp(input: ulid) -> Timestamp {
// 946684800000 is the number of milliseconds between 1970-01-01 and 2000-01-01
let inner = InnerUlid(input.0).timestamp_ms() as i64 - 946_684_800_000;
Timestamp::try_from(inner * 1000).unwrap()
let inner_seconds = (InnerUlid(input.0).timestamp_ms() as f64) / 1000.0;
to_timestamp(inner_seconds).into()
}

#[pg_extern(immutable, parallel_safe)]
Expand Down

0 comments on commit 277f114

Please sign in to comment.