diff --git a/src/commands/archive.rs b/src/commands/archive.rs index 25f1dfd..905d66c 100644 --- a/src/commands/archive.rs +++ b/src/commands/archive.rs @@ -2,13 +2,13 @@ use std::convert::TryFrom; use std::io::{BufRead, Write}; use clap::ArgMatches; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, Utc, Duration}; use regex::Regex; use crate::database::Database; use crate::error::{Error, Result}; use crate::commands::{Command, Facts}; -use crate::timeparse::parse_time; +use crate::timeparse::{parse_time, parse_duration}; use crate::old::{entries_or_warning, time_or_warning}; use crate::formatters::text; use crate::regex::parse_regex; @@ -20,6 +20,7 @@ pub struct Args { start: Option>, end: Option>, grep: Option, + time: Option, fake: bool, sheet: Option, } @@ -32,6 +33,7 @@ impl<'a> TryFrom<&'a ArgMatches<'a>> for Args { start: matches.value_of("start").map(parse_time).transpose()?, end: matches.value_of("end").map(parse_time).transpose()?, grep: matches.value_of("grep").map(parse_regex).transpose()?, + time: matches.value_of("time").map(parse_duration).transpose()?, fake: matches.is_present("fake"), sheet: matches.value_of("sheet").map(|s| s.to_owned()), }) @@ -63,6 +65,11 @@ impl<'a> Command<'a> for ArchiveCommand { entries.retain(|e| re.is_match(&e.note.clone().unwrap_or_default())); } + if let Some(time) = args.time { + // archive the maximum amount of consecutive entries whose + // accumulated time is not bigger that `time`. + } + if args.fake { let (entries, _) = entries_or_warning(entries, &streams.db)?; diff --git a/src/timeparse.rs b/src/timeparse.rs index abcdfdb..815b557 100644 --- a/src/timeparse.rs +++ b/src/timeparse.rs @@ -157,6 +157,10 @@ pub fn parse_time(input: &str) -> Result> { Err(Error::DateTimeParseError(input.into())) } +pub fn parse_duration(input: &str) -> Result { + todo!() +} + #[cfg(test)] mod tests { use chrono::{TimeZone, Duration};