Compare commits

..

3 Commits

Author SHA1 Message Date
Bel LaPointe
7463ca2069 default since is today 2023-12-07 09:14:44 -08:00
Bel LaPointe
1235b38636 timestamps from local timezone instead of utc 2023-12-07 09:09:26 -08:00
Bel LaPointe
cf47c63bd7 --since as local timezone 2023-12-07 09:09:17 -08:00

View File

@@ -4,7 +4,7 @@ use std::fs::File;
use std::time::{SystemTime, UNIX_EPOCH, Duration};
use std::ops::{Add, Sub};
use clap::Parser;
use chrono::DateTime;
use chrono::{TimeZone, Local, Timelike};
#[derive(Debug, Parser)]
struct Flags {
@@ -108,19 +108,17 @@ fn parse_time(since: &Option<String>) -> Result<SystemTime, String> {
match since {
Some(since) => {
match chrono::NaiveDate::parse_from_str(since, "%Y-%m-%d") {
Ok(dt) => {
Ok(nd) => {
let ndt = nd.and_hms_opt(1, 1, 1).unwrap();
let dt = Local.from_local_datetime(&ndt).unwrap();
Ok(UNIX_EPOCH.add(
Duration::from_secs(
dt.and_hms_opt(1, 1, 1)
.unwrap()
.timestamp() as u64
)
Duration::from_secs(dt.timestamp() as u64)
))
},
Err(msg) => Err(format!("failed to parse {}: {}", since, msg)),
}
},
None => Ok(SystemTime::now().sub(Duration::from_secs(60*60*24*7))),
None => Ok(SystemTime::now().sub(Duration::from_secs(Local::now().hour() as u64*60*60))),
}
}
@@ -222,7 +220,7 @@ impl X {
}
fn timestamp(&self) -> String {
let dt = DateTime::from_timestamp(self.t, 0).unwrap();
let dt = Local.timestamp_opt(self.t, 0).unwrap();
dt.format("%Y-%m-%d").to_string()
}
}