timetracking-rs: Tracking Hours in Rust
I worked with Technology for a long time. I created a Python script 10 years ago to manage my working hours for control, observability, backpressure purposes. Last Friday night(What a nerd thing to do, I know), I re-wrote this script into a Rust program. I always like to build my own tools, for several reasons, like make my work more productive or just because I want an excuse to do something useful for me in a language that I liked. It took me about 4h to figure out how to do this in Rust. There were 2 basic challenges with was Strings(OH I hate Strings in Rust) and working effectively with Data/Time math operations. I would 2 hours figure it out and making this work and 2 other hours refactoring the code to make it better. Overall code with Rust is pretty productive and fun however Strings and pain in the ass. So I’m using this program every day (decommission my old python script) — so this might be useful for you too. Let’s get started.
Show me the code
So we have 2 Rust files here: main, time_tracking, time_utils, and model. main we have the main application which reads the configs from the main arguments vector and parses it into a model::TimeTrackingData Struct.
The model files have structs for config and time tracking math operations. time_utils use chrono and bdays in order todo the date/time math I need for the program to work. The time_tracking has the report building pretty much and calls the hours calculations.
The complete code is here: https://github.com/diegopacheco/timetracking.rs
Originally published at http://diego-pacheco.blogspot.com on May 3, 2020.