You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing negative NaiveDateTime timestamps with #[serde(with = "ts_milliseconds")] (and other implementations) fails.
use chrono::{NaiveDateTime};// 0.4.19use chrono::naive::serde::ts_milliseconds::deserialize as from_milli_ts;use serde::Deserialize;#[derive(Deserialize)]structS{#[serde(deserialize_with = "from_milli_ts")]time:NaiveDateTime}fnexample() -> Result<S, serde_json::Error>{let my_s:S = serde_json::from_str(r#"{ "time": -1 }"#)?;Ok(my_s)}fnmain(){let value = -1;let r0 = value / 1000;let r1 = (value % 1000);// this is the implementation in chrono::naive::serde::ts_millisecondslet r = NaiveDateTime::from_timestamp_opt(
value / 1000,((value % 1000)*1_000_000)asu32);// conversion into u32 fails for negative values println!("{:?} {} {}", r, r0, r1);example().unwrap();}
The text was updated successfully, but these errors were encountered:
Parsing negative NaiveDateTime timestamps with #[serde(with = "ts_milliseconds")] (and other implementations) fails.
The text was updated successfully, but these errors were encountered: