Compare commits
No commits in common. "1d8eb97e2a04b75f33bce011fedcf61914dfde0d" and "dd62aaad99553ac8f32070c49a08b6ce52b2b5e8" have entirely different histories.
1d8eb97e2a
...
dd62aaad99
1 changed files with 22 additions and 10 deletions
32
src/main.rs
32
src/main.rs
|
@ -5,21 +5,29 @@ use std::{env, io};
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
if args.len() == 1
|
// TODO: change expected length to rfc3339
|
||||||
|| !(args[1].len() == 8 as usize
|
// if args.len() == 1 || args[1].len() != 8 as usize {
|
||||||
|| args[1].len() == 19 as usize
|
// println!("usage: since hh:mm:ss");
|
||||||
|| args[1].len() >= 21 as usize)
|
// std::process::abort();
|
||||||
{
|
// }
|
||||||
println!("usage: since hh:mm:ss"); //8
|
|
||||||
println!("usage: since yyyy-mm-dd hh:mm:ss"); //19
|
|
||||||
println!("usage: since <RFC 3339 timestamp>"); //21
|
|
||||||
std::process::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
let buffer = &args[1];
|
let buffer = &args[1];
|
||||||
|
|
||||||
|
//println!("{buffer}");
|
||||||
|
|
||||||
let tz = *Local::now().offset();
|
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>;
|
let timestamp: DateTime<Local>;
|
||||||
if let Some(t) = buffer.parse::<DateTime<Local>>().ok() {
|
if let Some(t) = buffer.parse::<DateTime<Local>>().ok() {
|
||||||
timestamp = t;
|
timestamp = t;
|
||||||
|
@ -36,8 +44,12 @@ fn main() -> io::Result<()> {
|
||||||
std::process::abort();
|
std::process::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: is local appropriate here?
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
|
|
||||||
|
// println!("{}", timestamp.to_rfc3339());
|
||||||
|
// println!("{}", now.to_rfc3339());
|
||||||
|
|
||||||
let delta = DateTime::signed_duration_since(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;
|
||||||
|
|
Loading…
Reference in a new issue