use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeDelta, Utc}; use clap::Parser; #[derive(Parser, Debug)] struct Args { time: Option, // date: Option, // time: Option, // time: Option, // #[arg(long)] // zone: Ti } fn main() { let args = Args::parse(); let stamp = if let Some(time) = args.time { let time = DateTime::parse_from_rfc2822(&time).unwrap(); println!("time: {}", time); println!("time: {}", time.to_rfc2822()); time.with_timezone(&Utc) } else { let now = Utc::now(); println!("Now: {}", now.with_timezone(&chrono::Local)); now }; let unix = stamp.timestamp(); let stamp = stamp.with_timezone(&chrono::Local); println!(" {}", unix, stamp.format("%A, %B %-d, %Y at %-H:%M %p")); println!(" {}", unix, stamp.format("%B %-d, %Y at %-H:%M %p")); println!(" {}", unix, stamp.format("%B %-d, %Y")); println!(" {}", unix, stamp.format("%-m/%-d/%y")); println!(" {}", unix, stamp.format("%-H:%M:%S %A")); println!(" {}", unix, stamp.format("%-H:%M %A")); let diff = stamp.with_timezone(&Utc) - Utc::now(); let wrap = if diff > TimeDelta::zero() { |num: i64, word: &str| format!("In {num} {word}") } else { |num: i64, word: &str| format!("{num} {word} ago") }; let abs_diff = diff.abs(); let words = if abs_diff.num_days() > 0 { wrap(abs_diff.num_days() + i64::from(abs_diff.num_hours() >= 12), "days") } else if abs_diff.num_hours() > 0 { wrap(abs_diff.num_hours(), "hours") } else if abs_diff.num_minutes() > 0 { wrap(abs_diff.num_minutes(), "minutes") } else if abs_diff.num_seconds() > 0 { wrap(abs_diff.num_seconds(), "seconds") } else { format!("now") }; println!(" {}", unix, words); }