a simple start to the archive-by-hours project
This commit is contained in:
parent
62d432b5ba
commit
d18319fd33
|
@ -2,13 +2,13 @@ use std::convert::TryFrom;
|
||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc, Duration};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::commands::{Command, Facts};
|
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::old::{entries_or_warning, time_or_warning};
|
||||||
use crate::formatters::text;
|
use crate::formatters::text;
|
||||||
use crate::regex::parse_regex;
|
use crate::regex::parse_regex;
|
||||||
|
@ -20,6 +20,7 @@ pub struct Args {
|
||||||
start: Option<DateTime<Utc>>,
|
start: Option<DateTime<Utc>>,
|
||||||
end: Option<DateTime<Utc>>,
|
end: Option<DateTime<Utc>>,
|
||||||
grep: Option<Regex>,
|
grep: Option<Regex>,
|
||||||
|
time: Option<Duration>,
|
||||||
fake: bool,
|
fake: bool,
|
||||||
sheet: Option<String>,
|
sheet: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -32,6 +33,7 @@ impl<'a> TryFrom<&'a ArgMatches<'a>> for Args {
|
||||||
start: matches.value_of("start").map(parse_time).transpose()?,
|
start: matches.value_of("start").map(parse_time).transpose()?,
|
||||||
end: matches.value_of("end").map(parse_time).transpose()?,
|
end: matches.value_of("end").map(parse_time).transpose()?,
|
||||||
grep: matches.value_of("grep").map(parse_regex).transpose()?,
|
grep: matches.value_of("grep").map(parse_regex).transpose()?,
|
||||||
|
time: matches.value_of("time").map(parse_duration).transpose()?,
|
||||||
fake: matches.is_present("fake"),
|
fake: matches.is_present("fake"),
|
||||||
sheet: matches.value_of("sheet").map(|s| s.to_owned()),
|
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()));
|
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 {
|
if args.fake {
|
||||||
let (entries, _) = entries_or_warning(entries, &streams.db)?;
|
let (entries, _) = entries_or_warning(entries, &streams.db)?;
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,10 @@ pub fn parse_time(input: &str) -> Result<DateTime<Utc>> {
|
||||||
Err(Error::DateTimeParseError(input.into()))
|
Err(Error::DateTimeParseError(input.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_duration(input: &str) -> Result<Duration> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use chrono::{TimeZone, Duration};
|
use chrono::{TimeZone, Duration};
|
||||||
|
|
Loading…
Reference in New Issue