diff options
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 | 
