diff --git a/Cargo.lock b/Cargo.lock index 35bd882..5aee76c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "time-track" -version = "2.0.0" +version = "2.0.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5348706..f3dc1a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "time-track" -version = "2.0.0" +version = "2.0.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 7541cd5..945df04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,15 +10,17 @@ use args::Args; fn main() -> Result<()> { let args = Args::parse(); - println!("{:?}", args); let stdin = io::stdin(); + println!("Input times one per line. Send an EOF character to finish inputting..."); let mut lines: Vec = vec![]; for line in stdin.lock().lines() { lines.push(line.expect("Issues when reading from stdin")); } + // This is immeidately going to be turned back into a DateTime, which the doc says is fine + #[allow(deprecated)] let midnight = Local::now().date().and_hms_opt(0, 0, 0).ok_or(anyhow!("Expected midnight to exist"))?; - let times = time::from_stream(&midnight.date(), lines.iter())?; + let times = time::from_stream(&midnight, lines.iter())?; let mut total_minutes: i64 = 0; let mut first: Option> = None; diff --git a/src/time.rs b/src/time.rs index dd4cbd8..787041d 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,9 +1,9 @@ -use chrono::{Duration, Local, DateTime, Date}; +use chrono::{Duration, Local, DateTime}; use anyhow::{Result, anyhow}; use std::iter::Iterator; use regex::Regex; -fn parse_datetime(reference_date: &Date, s: &str) -> Result> { +fn parse_datetime(reference_date: &DateTime, s: &str) -> Result> { let re = Regex::new(r"^\s*([12]?\d):([012345]\d)\s*$")?; let (_, [hrs, mins]) = re.captures(s).ok_or(anyhow!(format!("Failed to parse \"{s}\" as a time")))?.extract(); let mins: u32 = mins.parse()?; @@ -15,10 +15,11 @@ fn parse_datetime(reference_date: &Date, s: &str) -> Result2} not a real time", hrs, mins)))?) } -pub fn from_stream<'a>(reference_date: &Date, stream: impl Iterator) -> Result>> { +pub fn from_stream<'a>(reference_date: &DateTime, stream: impl Iterator) -> Result>> { let mut durations: Vec> = vec![]; for val in stream { durations.push(parse_datetime(reference_date, val)?);