Skip to content

Commit 302cf46

Browse files
committed
Handle negative nano seconds
1 parent e1a5e77 commit 302cf46

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/jiff-aws/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ impl ConvertJiffTypes for DateTime {
7373
type Error = jiff::Error;
7474

7575
fn from_timestamp(timestamp: Timestamp) -> Self {
76-
DateTime::from_secs_and_nanos(
77-
timestamp.as_second(),
78-
timestamp.subsec_nanosecond() as u32,
79-
)
76+
let nanos = if timestamp.subsec_nanosecond() < 0 {
77+
(1_000_000_000 + timestamp.subsec_nanosecond()) as u32
78+
} else {
79+
timestamp.subsec_nanosecond() as u32
80+
};
81+
82+
DateTime::from_secs_and_nanos(timestamp.as_second(), nanos)
8083
}
8184

8285
fn from_zoned(zoned: Zoned) -> Self {
8386
let timestamp = zoned.timestamp();
84-
DateTime::from_secs_and_nanos(
85-
timestamp.as_second(),
86-
timestamp.subsec_nanosecond() as u32,
87-
)
87+
Self::from_timestamp(timestamp)
8888
}
8989

9090
fn try_into_zoned(self) -> Result<Zoned, Self::Error> {

0 commit comments

Comments
 (0)