Browse Source

Add till command

This will show when you can leave work after 8 hours of presence.
master
Andreas Linz 2 years ago
parent
commit
2fe3fe21d2
No known key found for this signature in database GPG Key ID: 8DEF5099A0822620
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      src/main.rs

+ 12
- 0
src/main.rs View File

@ -160,6 +160,7 @@ fn usage(program: &str) -> String {
usage | help: shows this message
begin | stop: begin or stop work
pause | resume: starts/stops a pause
till: shows the time to leave after 8 hours
show [yyyy-mm-dd]: prints work time for given date of today's when absent",
program
)
@ -189,6 +190,7 @@ fn main() -> Result<(), TTError> {
"show" => show(&conn, args.pop_front())?,
"begin" | "stop" => record(&conn, State::Work)?,
"pause" | "resume" => record(&conn, State::Pause)?,
"till" => till(&conn)?,
_ => {
print_usage(&program);
return Err(TTError::UnknownCommand);
@ -198,6 +200,16 @@ fn main() -> Result<(), TTError> {
Ok(())
}
fn till(conn: &rusqlite::Connection) -> Result<(), TTError> {
let mut records = recs_at_date(&conn, Local::today().naive_local())?;
records.push(Record::new(State::Work));
if let Some(dur) = work_dur(&records) {
let till = Local::now() + Duration::hours(8) - dur;
println!("{}", till.format("%H:%M"));
}
Ok(())
}
fn show(conn: &rusqlite::Connection, date_arg: Option<String>) -> Result<(), TTError> {
let parsed_date = if let Some(date) = date_arg {
NaiveDate::parse_from_str(&date, "%F") // ISO 8601

Loading…
Cancel
Save