zenhob / hcl

Command-line tool for manipulating Harvest timesheets
http://zenhob.github.io/hcl
MIT License
223 stars 45 forks source link

Add date argument to `log` command #86

Open teddywing opened 6 years ago

teddywing commented 6 years ago

Adds an optional date argument to the log command that can be specified just before the task alias.

Some examples from @skoppelmanCC:

hcl log yesterday @documentation +2 Ran spellcheck
hcl log 3 days ago @wireframes +3.5
hcl log last friday @admin +1 filed timesheets

command_test.rb(#test_start): Update expected method call arguments with spent_at. Now that we're passing in spent_at, the expected arguments should include it.

utility_test.rb: Add tests for #get_date

Fixes #83.

teddywing commented 6 years ago

Huh, just realised this doesn't actually work correctly. I had been testing with 'yesterday', but that was just a fluke because the stop command handles both today and yesterday (https://github.com/zenhob/hcl/blob/cea2bbe0d1b2c9629d7fab397093856580a9e099/lib/hcl/commands.rb#L127).

Assuming I need to get DayEntry.with_timer to use the provided date in order to get this to work correctly.

teddywing commented 6 years ago

Came up with a new mechanism for doing logging and handling past dates. This duplicates the work of Commands#start while introducing a way to parse a date as an optional first argument, and instead of calling task.start, it calls task.add. This enables the time to be logged on the specified date without ever having to deal with stopping timers.

With this latest change, I've duplicated most of the contents of Commands#start, and haven't figured out a good strategy to eliminate that duplication. If that's a concern, I'd appreciate any ideas to simplify the code.