Skip to content

Commit

Permalink
fix: null support in timestamp and date
Browse files Browse the repository at this point in the history
  • Loading branch information
chloeminkyung committed Jan 25, 2023
1 parent 5356f9c commit e8f5444
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dozer-types/src/types/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl Field {
match self {
Field::Timestamp(t) => Some(*t),
Field::String(s) => DateTime::parse_from_rfc3339(s.as_str()).ok(),
Field::Null => Some(DateTime::from(Utc.timestamp_millis(0))),
_ => None,
}
}
Expand All @@ -373,6 +374,7 @@ impl Field {
match self {
Field::Date(d) => Some(*d),
Field::String(s) => NaiveDate::parse_from_str(s, "%Y-%m-%d").ok(),
Field::Null => Some(Utc.timestamp_millis(0).naive_utc().date()),
_ => None,
}
}
Expand Down Expand Up @@ -844,8 +846,8 @@ pub mod tests {
assert!(field.to_text().is_some());
assert!(field.to_binary().is_none());
assert!(field.to_decimal().is_some());
assert!(field.to_timestamp().is_none());
assert!(field.to_date().is_none());
assert!(field.to_timestamp().is_some());
assert!(field.to_date().is_some());
assert!(field.to_bson().is_none());
assert!(field.to_null().is_some());
}
Expand Down

0 comments on commit e8f5444

Please sign in to comment.