diff options
| author | Teddy Wing | 2018-01-27 00:31:57 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-01-31 20:47:10 +0100 | 
| commit | 873325ebce6d0451263d115a8f02f40e0a6fbd40 (patch) | |
| tree | 861fada27872332705c59c41b8cf045f86bd57fe /lib | |
| parent | cea2bbe0d1b2c9629d7fab397093856580a9e099 (diff) | |
| download | hcl-log-for-past-days--squashed.tar.bz2 | |
Add date argument to `log` commandlog-for-past-days--squashed
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
Commands#log:
Copy over the contents of `Commands#start` and replace `task.start` with
`task.add`. This allows us to log the time without actually starting a
timer (and thus having to subsequently stop that timer).
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.
command_test.rb(#test_log_failure):
Delete this test because I've rewritten the `Commands#log` method to no
longer use timers.
utility_test.rb: Add tests for `#get_date`
Fixes #83.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl/app.rb | 2 | ||||
| -rw-r--r-- | lib/hcl/commands.rb | 13 | ||||
| -rw-r--r-- | lib/hcl/task.rb | 3 | ||||
| -rw-r--r-- | lib/hcl/utility.rb | 10 | 
4 files changed, 23 insertions, 5 deletions
| diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 4f2530b..321b3d5 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -113,7 +113,7 @@ Commands:      hcl stop [<message>]      # log a task and time without leaving a timer running -    hcl log @<task_alias> [+<time>] [<message>] +    hcl log [<date>] @<task_alias> [+<time>] [<message>]      # resume the last stopped timer or a specific task      hcl resume [@<task_alias>] diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index 9800c95..7c2eac8 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -118,9 +118,16 @@ module HCl      end      def log *args -      fail "There is already a timer running." if DayEntry.with_timer(http) -      start *args -      stop +      date = get_date(args) +      starting_time = get_starting_time args +      task = get_task args +      if task.nil? +        fail "Unknown task alias, try one of the following: ", aliases.join(', ') +      end +      timer = task.add http, +        :spent_at => date, +        :starting_time => starting_time, +        :note => args.join(' ')      end      def stop *args diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb index 89e3b97..313fdf1 100644 --- a/lib/hcl/task.rb +++ b/lib/hcl/task.rb @@ -50,12 +50,13 @@ module HCl      def add http, opts        notes = opts[:note]        starting_time = opts[:starting_time] || 0 +      spent_at = opts[:spent_at] || Date.today        DayEntry.new http.post("daily/add", {          notes: notes,          hours: starting_time,          project_id: project.id,          task_id: id, -        spent_at: Date.today +        spent_at: spent_at        })      end diff --git a/lib/hcl/utility.rb b/lib/hcl/utility.rb index fd01901..6c0ec8b 100644 --- a/lib/hcl/utility.rb +++ b/lib/hcl/utility.rb @@ -1,3 +1,5 @@ +require 'chronic' +  module HCl    class CommandError < StandardError; end    module Utility @@ -35,6 +37,14 @@ module HCl        end      end +    def get_date args +      ident_index = args.index {|a| a[0] == '@' } + +      unless ident_index.nil? +        Chronic.parse(args.shift(ident_index).join(' ')) +      end +    end +      def current_time        Time.now.strftime('%I:%M %p').downcase      end | 
