Writing a simple time tracker in Rust

Today was another Red Hat Day of Learning. Half a year ago I started learning Rust, but have not really done much with it since then. I did try to port simple-term, but that was quickly thwarted by the unmaintained and broken vte Rust binding for GTK3 – that issue is still way over my head, I didn’t make much progress after two hours of monkey patching.

I have used gtimelog to track my work for my entire professional life (since 2004). I recently recommended it to my wife, but Because Reasonsâ„¢ it does not run on her SLES work machine. She has used some simple CLI time tracking app, but isn’t satisfied with that. Thus here was the idea and motivation – let’s write a gtimelog-like CLI time tracker in Rust!

It should have the same data format, and in fact the same file~/.gtimelog/timelog.txt, so that I can freely switch between gtimelog and that CLI tracker. Other than that, it does not really need to do much: Enter a new entry after finishing some task (or break), group them, and tally up the per-activity, current-day, and current-week work and slack times.

So today, after long hours of RTFM, stackoverflowing, and brooding over compiler errors, rtimelog was born! When I start it, it looks like this:

Work done today:
10 h 45 min: day of learning: time logger in Rust
 3 h 44 min: **
 0 h 18 min: team meeting
 0 h 43 min: day of learning: create test and release workflows for rtimelog
-------
Total work done: 11 h 46 min
Total slacking: 3 h 44 min


command (:h for help) or entry:

If you know gtimelog, this should be very familiar to you – that is deliberate đŸ˜‰.

It does the basic stuff from above, the numbers exactly match the ones that I get in gtimelog, and I applied an appropriate amount of effort on the unit tests (for the limited time, anyway) to make sure that it does not screw up too much.

I also added workflows for unit tests and auto-building Linux, Windows, and MacOS binaries for releases.

Next steps that I want to do:

  • Show time since last entry (“uncommitted current task”)
  • Add an :edit command to launch $EDITOR on timelog.txt
  • Add a noninteractive CLI, like rtimelog add "team meeting" or rtimelog weekly
  • Clean up the code with rustfmt and clippy
  • Ideally, tab completion for common/repeated tasks Not sure how involved that is, for that I might need a full ncurses UI to be tasteful?

This was an intense, but successful day, and I already feel a lot less intimidated by Rust now. Nevertheless, if you are a Rust developer, I would really appreciate some hints how to improve the code – I’m sure this can be reduced by half, and made much more elegant.