Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Dec 18, 2024
1 parent 2765e78 commit 5a1b6d3
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions rust/cubeorchestrator/src/query_result_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,42 @@ pub const MEMBER_SEPARATOR: &str = ".";
pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimitive {
match value {
DBResponseValue::DateTime(dt) if type_ == "time" || type_.is_empty() => {
DBResponsePrimitive::String(dt.with_timezone(&Utc).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
DBResponsePrimitive::String(
dt.with_timezone(&Utc)
.format("%Y-%m-%dT%H:%M:%S%.3f")
.to_string(),
)
}
DBResponseValue::Primitive(DBResponsePrimitive::String(ref s)) if type_ == "time" => {
let formatted = DateTime::parse_from_rfc3339(s)
.map(|dt| dt.format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
.or_else(|_| {
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f")
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f").map(|dt| {
Utc.from_utc_datetime(&dt)
.format("%Y-%m-%dT%H:%M:%S%.3f")
.to_string()
})
})
.or_else(|_| {
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S")
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S").map(|dt| {
Utc.from_utc_datetime(&dt)
.format("%Y-%m-%dT%H:%M:%S%.3f")
.to_string()
})
})
.or_else(|_| {
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %Z")
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %Z").map(|dt| {
Utc.from_utc_datetime(&dt)
.format("%Y-%m-%dT%H:%M:%S%.3f")
.to_string()
})
})
.or_else(|_| {
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %:z")
.map(|dt| Utc.from_utc_datetime(&dt).format("%Y-%m-%dT%H:%M:%S%.3f").to_string())
NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.3f %:z").map(|dt| {
Utc.from_utc_datetime(&dt)
.format("%Y-%m-%dT%H:%M:%S%.3f")
.to_string()
})
})
.unwrap_or_else(|_| s.clone());
DBResponsePrimitive::String(formatted)
Expand Down

0 comments on commit 5a1b6d3

Please sign in to comment.