Skip to content

Commit 673aace

Browse files
committed
feat(timestamp_ns): fix math for timestamptz_nanos
1 parent 0b28660 commit 673aace

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/iceberg/src/spec/values.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl Datum {
421421
PrimitiveLiteral::TimestampNs(i64::from_le_bytes(bytes.try_into()?))
422422
}
423423
PrimitiveType::TimestamptzNs => {
424-
PrimitiveLiteral::TimestampNs(i64::from_le_bytes(bytes.try_into()?))
424+
PrimitiveLiteral::TimestamptzNs(i64::from_le_bytes(bytes.try_into()?))
425425
}
426426
PrimitiveType::String => {
427427
PrimitiveLiteral::String(std::str::from_utf8(bytes)?.to_string())
@@ -846,7 +846,7 @@ impl Datum {
846846
/// use iceberg::spec::Datum;
847847
/// let t = Datum::timestamptz_nanos(1000);
848848
///
849-
/// assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.001 UTC");
849+
/// assert_eq!(&format!("{t}"), "1970-01-01 00:00:00.000001 UTC");
850850
/// ```
851851
pub fn timestamptz_nanos(value: i64) -> Self {
852852
Self {
@@ -1864,7 +1864,7 @@ impl Literal {
18641864
.to_string(),
18651865
)),
18661866
PrimitiveLiteral::TimestamptzNs(val) => Ok(JsonValue::String(
1867-
timestamptz::microseconds_to_datetimetz(val)
1867+
timestamptz::nanoseconds_to_datetimetz(val)
18681868
.format("%Y-%m-%dT%H:%M:%S%.f+00:00")
18691869
.to_string(),
18701870
)),
@@ -2049,7 +2049,7 @@ mod timestamptz {
20492049
pub(crate) fn nanoseconds_to_datetimetz(nanos: i64) -> DateTime<Utc> {
20502050
let (secs, rem) = (nanos / 1_000_000_000, nanos % 1_000_000_000);
20512051

2052-
DateTime::from_timestamp(secs, rem as u32 * 1_000).unwrap()
2052+
DateTime::from_timestamp(secs, rem as u32).unwrap()
20532053
}
20542054
}
20552055

0 commit comments

Comments
 (0)