diff --git a/apps/vault/src/prereqs.rs b/apps/vault/src/prereqs.rs index fbbb3bc48..70dc0c0ce 100644 --- a/apps/vault/src/prereqs.rs +++ b/apps/vault/src/prereqs.rs @@ -211,7 +211,7 @@ pub(crate) fn ntp_updater(time_conn: xous::CID) { match result { Ok(time) => { log::debug!("Got NTP time: {}.{}", time.sec(), time.sec_fraction()); - let current_time = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0) + let current_time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() + chrono::Duration::seconds(time.sec() as i64); log::debug!("Setting UTC time: {:?}", current_time.to_string()); xous::send_message( diff --git a/apps/vault/src/storage.rs b/apps/vault/src/storage.rs index 18b73730e..f8b562aa3 100644 --- a/apps/vault/src/storage.rs +++ b/apps/vault/src/storage.rs @@ -766,8 +766,8 @@ impl From for Vec { /// target fn utc_now() -> DateTime { let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch"); - let naive = NaiveDateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos() as u32); - DateTime::from_utc(naive, Utc) + let naive = NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos() as u32).unwrap(); + DateTime::from_naive_utc_and_offset(naive, Utc) } pub fn hex(data: Vec) -> String { diff --git a/apps/vault/src/vault_api.rs b/apps/vault/src/vault_api.rs index fec554755..1a1b5b191 100644 --- a/apps/vault/src/vault_api.rs +++ b/apps/vault/src/vault_api.rs @@ -63,7 +63,10 @@ pub fn atime_to_str(req_atime: u64) -> String { request_str.push_str(t!("vault.u2f.appinfo.never", locales::LANG)); } else { let now = utc_now(); - let atime = DateTime::::from_utc(NaiveDateTime::from_timestamp(req_atime as i64, 0), Utc); + let atime = DateTime::::from_naive_utc_and_offset( + NaiveDateTime::from_timestamp_opt(req_atime as i64, 0).unwrap(), + Utc, + ); // avoid format! macro, it is too slow. if now.signed_duration_since(atime).num_days() > 1 { request_str.push_str(t!("vault.u2f.appinfo.last_authtime", locales::LANG)); @@ -90,8 +93,8 @@ pub fn atime_to_str(req_atime: u64) -> String { /// target pub fn utc_now() -> DateTime { let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch"); - let naive = NaiveDateTime::from_timestamp(now.as_secs() as i64, now.subsec_nanos() as u32); - DateTime::from_utc(naive, Utc) + let naive = NaiveDateTime::from_timestamp_opt(now.as_secs() as i64, now.subsec_nanos() as u32).unwrap(); + DateTime::from_naive_utc_and_offset(naive, Utc) } /// app info format: diff --git a/services/dns/src/time.rs b/services/dns/src/time.rs index 204fdc4b3..686cd317a 100644 --- a/services/dns/src/time.rs +++ b/services/dns/src/time.rs @@ -666,7 +666,7 @@ pub(crate) fn start_time_ux() { match result { Ok(time) => { log::info!("Got NTP time: {}.{}", time.sec(), time.sec_fraction()); - let current_time = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0) + let current_time = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() + chrono::Duration::seconds(time.sec() as i64); log::info!("Setting UTC time: {:?}", current_time.to_string()); xous::send_message( @@ -744,9 +744,17 @@ pub(crate) fn start_time_ux() { } log::info!("Setting time: {}/{}/{} {}:{}:{}", months, days, years, hours, mins, secs); - let new_dt = chrono::FixedOffset::east((tz_offset_ms / 1000) as i32) - .ymd(years as i32 + 2000, months as u32, days as u32) - .and_hms(hours as u32, mins as u32, secs as u32); + let new_dt = chrono::FixedOffset::east_opt((tz_offset_ms / 1000) as i32) + .unwrap() + .with_ymd_and_hms( + years as i32 + 2000, + months as u32, + days as u32, + hours as u32, + mins as u32, + secs as u32, + ) + .unwrap(); xous::send_message( timeserver_cid, Message::new_scalar( diff --git a/services/shellchat/src/cmds/rtc_cmd.rs b/services/shellchat/src/cmds/rtc_cmd.rs index e88a3d3cb..fc95c4371 100644 --- a/services/shellchat/src/cmds/rtc_cmd.rs +++ b/services/shellchat/src/cmds/rtc_cmd.rs @@ -36,8 +36,8 @@ impl<'a> ShellCmdApi<'a> for RtcCmd { let mut localtime = llio::LocalTime::new(); if let Some(timestamp) = localtime.get_local_time_ms() { // we "say" UTC but actually local time is in whatever the local time is - let dt = chrono::DateTime::::from_utc( - NaiveDateTime::from_timestamp(timestamp as i64 / 1000, 0), + let dt = chrono::DateTime::::from_naive_utc_and_offset( + NaiveDateTime::from_timestamp_opt(timestamp as i64 / 1000, 0).unwrap(), chrono::offset::Utc, ); let timestr = dt.format("%m/%d/%Y %T").to_string(); diff --git a/services/status/src/main.rs b/services/status/src/main.rs index 2f8f32eb7..d952f79d9 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -530,8 +530,8 @@ fn wrapped_main() -> ! { // once we have unlocked the PDDB and know our timezone, we'll compare the embedded // timestamp to our current time, and delete the backup if it's too // old. - backup_time = Some(chrono::DateTime::::from_utc( - NaiveDateTime::from_timestamp(header.timestamp as i64, 0), + backup_time = Some(chrono::DateTime::::from_naive_utc_and_offset( + NaiveDateTime::from_timestamp_opt(header.timestamp as i64, 0).unwrap(), chrono::offset::Utc, )); } @@ -1234,8 +1234,8 @@ fn wrapped_main() -> ! { uptime_tv.clear_str(); if let Some(timestamp) = localtime.get_local_time_ms() { // we "say" UTC but actually local time is in whatever the local time is - let dt = chrono::DateTime::::from_utc( - NaiveDateTime::from_timestamp(timestamp as i64 / 1000, 0), + let dt = chrono::DateTime::::from_naive_utc_and_offset( + NaiveDateTime::from_timestamp_opt(timestamp as i64 / 1000, 0).unwrap(), chrono::offset::Utc, ); let timestr = dt.format("%H:%M %m/%d").to_string();