--since as local timezone

main
Bel LaPointe 2023-12-07 09:09:17 -08:00
parent 0f9711aaa1
commit cf47c63bd7
1 changed files with 5 additions and 7 deletions

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};
#[derive(Debug, Parser)]
struct Flags {
@ -108,13 +108,11 @@ 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)),