Skip to content

Commit ce4b8e7

Browse files
committed
another fix in datetime parsing
1 parent 29463d8 commit ce4b8e7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/cubeorchestrator/src/query_result_transform.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimiti
4949
.to_string()
5050
})
5151
})
52+
.or_else(|_| {
53+
NaiveDateTime::parse_from_str(s, "%Y-%m-%dT%H:%M:%S").map(|dt| {
54+
Utc.from_utc_datetime(&dt)
55+
.format("%Y-%m-%dT%H:%M:%S%.3f")
56+
.to_string()
57+
})
58+
})
5259
.or_else(|_| {
5360
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %Z").map(|dt| {
5461
Utc.from_utc_datetime(&dt)
@@ -715,6 +722,19 @@ mod tests {
715722
);
716723
}
717724

725+
#[test]
726+
fn test_transform_value_string_wo_mssec_w_t_to_time_valid_rfc3339() {
727+
let value = DBResponseValue::Primitive(DBResponsePrimitive::String(
728+
"2024-01-01T12:30:15".to_string(),
729+
));
730+
let result = transform_value(value, "time");
731+
732+
assert_eq!(
733+
result,
734+
DBResponsePrimitive::String("2024-01-01T12:30:15.000".to_string())
735+
);
736+
}
737+
718738
#[test]
719739
fn test_transform_value_string_with_tz_offset_to_time_valid_rfc3339() {
720740
let value = DBResponseValue::Primitive(DBResponsePrimitive::String(

0 commit comments

Comments
 (0)