feat: new parse formats
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
0848872af8
commit
dd62aaad99
1 changed files with 35 additions and 3 deletions
38
src/main.rs
38
src/main.rs
|
@ -13,12 +13,44 @@ fn main() -> io::Result<()> {
|
||||||
|
|
||||||
let buffer = &args[1];
|
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<Local>;
|
||||||
|
if let Some(t) = buffer.parse::<DateTime<Local>>().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?
|
// NOTE: is local appropriate here?
|
||||||
let timestamp = buffer.parse::<DateTime<Local>>().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 days = ((delta.num_seconds() / 60) / 60) / 24;
|
||||||
let hours = ((delta.num_seconds() / 60) / 60) % 24;
|
let hours = ((delta.num_seconds() / 60) / 60) % 24;
|
||||||
|
|
Loading…
Reference in a new issue