Skip to content

Commit 1a1684e

Browse files
committed
readyset-data: Parse BC timestamp without timezone
`TimestampTz::from_str()` can parse AD years (year 1 and higher) correctly for timestamp, timestamptz, and date. BC years are handled separately, but only parse timestamptz and date. This CL adds parsing of timestamps to BC years. Fixes: REA-4273 Release-Note-Core: Allow BC timestamps without a time zone. Change-Id: I4515fbc96bb752d65e9e64b60fa7c48ec8764eda Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7155 Tested-by: Buildkite CI Reviewed-by: Ethan Donowitz <ethan@readyset.io>
1 parent c5e4a1a commit 1a1684e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

readyset-data/src/timestamp.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ impl FromStr for TimestampTz {
260260
TIMESTAMP_TZ_PARSE_FORMAT,
261261
) {
262262
Ok(dt.into())
263+
} else if let Ok(dt) =
264+
NaiveDateTime::parse_from_str(&neg_year_str, TIMESTAMP_PARSE_FORMAT)
265+
{
266+
Ok(dt.into())
263267
} else {
264268
let d = NaiveDate::parse_from_str(&neg_year_str, DATE_FORMAT)?;
265269
Ok(d.into())
@@ -726,6 +730,7 @@ mod tests {
726730

727731
#[allow(clippy::zero_prefixed_literal)]
728732
let year_5_bce = -0004;
733+
// BC date with time zone
729734
assert_eq!(
730735
TimestampTz::from_str("0005-02-29 12:34:56+00 BC")
731736
.unwrap()
@@ -736,5 +741,16 @@ mod tests {
736741
.single()
737742
.unwrap()
738743
);
744+
// BC date without time zone
745+
assert_eq!(
746+
TimestampTz::from_str("0005-02-21 12:34:56 BC")
747+
.unwrap()
748+
.to_chrono(),
749+
chrono::FixedOffset::east_opt(0)
750+
.unwrap()
751+
.with_ymd_and_hms(year_5_bce, 2, 21, 12, 34, 56)
752+
.single()
753+
.unwrap()
754+
);
739755
}
740756
}

0 commit comments

Comments
 (0)