chore: update chrono obsolete methods and NaiveDateTime

This commit is contained in:
Jesús Pérez 2023-09-19 02:26:13 +01:00
parent d495ea4a8e
commit 42dc0ff7a3

View File

@ -1,5 +1,6 @@
use std::net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs};
use chrono::{DateTime,Utc,NaiveDateTime};
use chrono::NaiveDateTime;
//use chrono::{DateTime,Local, Utc,NaiveDateTime};
//use std::time::{UNIX_EPOCH, Duration};
pub fn get_socket_addr(bind: &str, port: u16) -> SocketAddr {
@ -49,10 +50,18 @@ pub fn path_timestamp(filepath: &str) -> u32 {
pub fn str_date_from_timestamp(timestamp: &str) -> String {
if timestamp.is_empty() { return String::from(""); }
let val: i64 = timestamp.parse().unwrap_or_default();
let dt = NaiveDateTime::from_timestamp_opt(val, 0).unwrap_or_default();
let datetime = DateTime::<Utc>::from_utc(dt, Utc);
let datetime = NaiveDateTime::from_timestamp_opt(val, 0).unwrap_or_default(); // (Local::now());
/*
let naive_utc = dt.naive_utc();
let offset = dt.offset().clone();
// Serialize, pass through FFI... and recreate the `DateTime`:
let datetime = DateTime::<Local>::from_naive_utc_and_offset(naive_utc, offset);
// let datetime = DateTime::<Utc>::from_ut(dt, Utc);
// let val = u64::try_from(timestamp.to_owned()).unwrap_or_default();
// let str_timestamp = UNIX_EPOCH + Duration::from_millis(val);
// let datetime = DateTime::<Utc>::from(str_timestamp);
*/
datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}