a simple start to the archive-by-hours project

This commit is contained in:
Abraham Toriz 2022-05-06 08:48:00 -05:00
parent 62d432b5ba
commit d18319fd33
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
2 changed files with 13 additions and 2 deletions

View File

@ -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<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
grep: Option<Regex>,
time: Option<Duration>,
fake: bool,
sheet: Option<String>,
}
@ -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)?;

View File

@ -157,6 +157,10 @@ pub fn parse_time(input: &str) -> Result<DateTime<Utc>> {
Err(Error::DateTimeParseError(input.into()))
}
pub fn parse_duration(input: &str) -> Result<Duration> {
todo!()
}
#[cfg(test)]
mod tests {
use chrono::{TimeZone, Duration};