From cf47c63bd76e7342bfec6d4e6d4caca06f2c04a4 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 7 Dec 2023 09:09:17 -0800 Subject: [PATCH] --since as local timezone --- src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ad08607..29397f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) -> Result { 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)),