Browse Source

Fix duration shown in show command

A temporary timestamp of type work is appended to the records so the
duration until now is shown and not that one between the first and last
database record.
This also converts the timestamp to UTC when selecting it from the
database, otherwise the database records would have an offset depending
on the local timezone¹.

¹ this screams for a test
master
Andreas Linz 2 years ago
parent
commit
2f7b42cbad
No known key found for this signature in database GPG Key ID: 8DEF5099A0822620
2 changed files with 22 additions and 2 deletions
  1. +18
    -0
      Makefile
  2. +4
    -2
      src/main.rs

+ 18
- 0
Makefile View File

@ -0,0 +1,18 @@
RUST_SRC=$(wildcard **/*.rs)
all: tt
install: tt
ifeq ($$EUID, 0)
@install --mode=0755 --verbose tt /usr/local/bin
else
@install --mode=0755 --verbose tt $$HOME/.local/bin
endif
tt: target/release/tt
@cp $< $@
target/release/tt: $(RUST_SRC)
cargo build --release
# remove debug information
strip $@

+ 4
- 2
src/main.rs View File

@ -141,7 +141,7 @@ fn prepare_database(conn: &rusqlite::Connection) -> Result {
fn recs_at_date(conn: &rusqlite::Connection, date: NaiveDate) -> Result<Vec<Record>, TTError> {
let next_date = date.succ();
let mut stmt = conn.prepare(
"SELECT timestamp, state FROM Timestamps WHERE timestamp >= ? AND timestamp < ? ORDER BY timestamp ASC",
"SELECT datetime(timestamp, 'utc'), state FROM Timestamps WHERE timestamp >= ? AND timestamp < ? ORDER BY timestamp ASC",
).map_err(TTError::RecordSelectionError)?;
let rec_iter = stmt
.query_map(&[&date, &next_date], Record::from_row)
@ -205,9 +205,11 @@ fn show(conn: &rusqlite::Connection, date_arg: Option) -> Result<(), TTE
} else {
Local::today().naive_local()
};
let mut records = recs_at_date(&conn, parsed_date)?;
records.push(Record::new(State::Work));
println!(
"{}",
format_duration(work_dur(&recs_at_date(&conn, parsed_date)?))
format_duration(work_dur(&records))
);
Ok(())
}

Loading…
Cancel
Save