Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

airbyte-to-flow: normalizing dates to date-time must use 00:00:00 #274

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions airbyte-to-flow/src/interceptors/normalize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::interceptors::fix_document_schema::traverse_jsonschema;
use dateparser::parse_with_timezone;
use chrono::{SecondsFormat, LocalResult, TimeZone};
use dateparser::parse_with;
use chrono::{SecondsFormat, LocalResult, TimeZone, NaiveTime};
use doc::ptr::Token;
use json::schema::formats::Format;
use json::validator::ValidationResult;
Expand Down Expand Up @@ -82,7 +82,9 @@ fn normalize_to_rfc3339(doc: &mut serde_json::Value, ptr: &doc::Pointer) {
match Format::DateTime.validate(&val) {
ValidationResult::Valid => (), // Already a valid date
_ => {
let parsed = parse_with_timezone(&val, &chrono::offset::Utc).or_else(|_|
let midnight_naive = NaiveTime::from_hms_opt(0, 0, 0).unwrap();

let parsed = parse_with(&val, &chrono::offset::Utc, midnight_naive).or_else(|_|
chrono::DateTime::parse_from_str(&val, "%Y-%m-%dT%H:%M:%S%.3f%z").map(|d| d.with_timezone(&chrono::Utc))
).or_else(|_|
chrono::DateTime::parse_from_str(&val, "%Y-%m-%dT%H:%M:%S%z").map(|d| d.with_timezone(&chrono::Utc))
Expand Down Expand Up @@ -348,7 +350,39 @@ mod tests {
"fractional_milliseconds": "2023-05-26T10:49:48.123Z"
}],
}),
)
),
(
serde_json::json!({
"type": "object",
"properties": {
"created": {
"type": "string",
"format": "date-time"
},
"nested": {
"type": "object",
"properties": {
"x": {
"type": ["string", "null"],
"format": "date-time"
}
}
}
}
}),
serde_json::json!({
"created": "2023-01-30",
"nested": {
"x": "2021-03-02"
}
}),
serde_json::json!({
"created": "2023-01-30T00:00:00Z",
"nested": {
"x": "2021-03-02T00:00:00Z"
}
}),
),
];

for (mut schema, mut input, expected) in cases {
Expand Down
Loading