diff --git a/src/main.rs b/src/main.rs index 3143b77..7ffee6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,44 @@ fn main() -> io::Result<()> { let buffer = &args[1]; + //println!("{buffer}"); + + let tz = *Local::now().offset(); + + // println!( + // "{}", + // NaiveDateTime::new( + // Local::now().date_naive(), + // NaiveTime::parse_from_str("12:00:00", "%H:%M:%S").unwrap() + // ) + // .and_local_timezone(tz) + // .single() + // .unwrap() + // ); + + let timestamp: DateTime; + if let Some(t) = buffer.parse::>().ok() { + timestamp = t; + } else if let Some(t) = NaiveDateTime::parse_from_str(buffer, "%Y-%m-%d %H:%M:%S").ok() { + timestamp = t.and_local_timezone(tz).single().unwrap().into(); + } else if let Some(t) = NaiveTime::parse_from_str(buffer, "%H:%M:%S").ok() { + timestamp = NaiveDateTime::new(Local::now().date_naive(), t) + .and_local_timezone(tz) + .single() + .unwrap() + .into(); + } else { + println!("Couldn't parse timestamp!"); + std::process::abort(); + } + // NOTE: is local appropriate here? - let timestamp = buffer.parse::>().unwrap(); + let now = Local::now(); - println!("{}", timestamp.to_rfc3339()); + // println!("{}", timestamp.to_rfc3339()); + // println!("{}", now.to_rfc3339()); - let delta = DateTime::signed_duration_since(Local::now(), timestamp); + let delta = DateTime::signed_duration_since(now, timestamp); let days = ((delta.num_seconds() / 60) / 60) / 24; let hours = ((delta.num_seconds() / 60) / 60) % 24;