Skip to content

Commit 4c124d8

Browse files
committed
another fix in datetime parsing
1 parent eae67bf commit 4c124d8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

rust/cubeorchestrator/src/query_result_transform.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimiti
3535
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f")
3636
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
3737
})
38+
.or_else(|_| {
39+
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S")
40+
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
41+
})
3842
.or_else(|_| {
3943
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %Z")
4044
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
@@ -677,6 +681,19 @@ mod tests {
677681
);
678682
}
679683

684+
#[test]
685+
fn test_transform_value_string_wo_mssec_to_time_valid_rfc3339() {
686+
let value = DBResponseValue::Primitive(DBResponsePrimitive::String(
687+
"2024-01-01 12:30:15".to_string(),
688+
));
689+
let result = transform_value(value, "time");
690+
691+
assert_eq!(
692+
result,
693+
DBResponsePrimitive::String("2024-01-01T12:30:15.000".to_string())
694+
);
695+
}
696+
680697
#[test]
681698
fn test_transform_value_string_with_tz_offset_to_time_valid_rfc3339() {
682699
let value = DBResponseValue::Primitive(DBResponsePrimitive::String(

0 commit comments

Comments
 (0)