Skip to content

Commit

Permalink
accept float unix timestamp (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
phiSgr authored and cjus committed Oct 21, 2024
1 parent c5d61e6 commit 79314c9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/framework-cli/src/utilities/validate_passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ impl<'de, 'a, S: SerializeValue> Visitor<'de> for &mut ValueVisitor<'a, S> {
E: Error,
{
match self.t {
ColumnType::DateTime => {
let seconds = v.trunc() as i64;
let nanos = ((v.fract() * 1_000_000_000.0).round() as u32).min(999_999_999);
let date = chrono::DateTime::from_timestamp(seconds, nanos)
.ok_or(E::custom("Invalid timestamp"))?;
self.write_to
.serialize_value(&date.to_rfc3339_opts(chrono::SecondsFormat::Nanos, true))
.map_err(Error::custom)
}
ColumnType::Float => self.write_to.serialize_value(&v).map_err(Error::custom),
_ => Err(Error::invalid_type(serde::de::Unexpected::Float(v), &self)),
}
Expand Down

0 comments on commit 79314c9

Please sign in to comment.