diff options
| author | Teddy Wing | 2018-01-31 21:08:30 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-01-31 21:08:30 +0100 | 
| commit | 948c511df10913548ad8646b14daaa992ff695d8 (patch) | |
| tree | f305bae9b4a832ce60044195b694e63f3f4ec6e1 | |
| parent | e820b8a2c7901e25231b68274fa3c853573e4fa0 (diff) | |
| parent | 873325ebce6d0451263d115a8f02f40e0a6fbd40 (diff) | |
| download | hcl-948c511df10913548ad8646b14daaa992ff695d8.tar.bz2 | |
Merge branch 'log-for-past-days--squashed--v2' into twtw
| -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 | ||||
| -rw-r--r-- | test/command_test.rb | 5 | ||||
| -rw-r--r-- | test/utility_test.rb | 8 | 
6 files changed, 31 insertions, 10 deletions
| diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index b4c9fd3..4065c46 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -114,7 +114,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 diff --git a/test/command_test.rb b/test/command_test.rb index 8536286..94ff673 100644 --- a/test/command_test.rb +++ b/test/command_test.rb @@ -31,11 +31,6 @@ class CommandTest < HCl::TestCase      assert_equal "taco.time: now\n", standard_output    end -  def test_log_failure -    HCl::DayEntry.expects(:with_timer).returns(stub) -    assert_raises(HCl::CommandError) { log "stuff" } -  end -    def test_tasks      FileUtils.rm_rf ENV['HCL_DIR']+"/cache"      register_uri(:get, '/daily', {:day_entries=>[], :projects=> [{ diff --git a/test/utility_test.rb b/test/utility_test.rb index b0fb09c..222d129 100644 --- a/test/utility_test.rb +++ b/test/utility_test.rb @@ -24,6 +24,14 @@ class UtilityTest < HCl::TestCase      assert_equal 0.25, get_starting_time(%w[ @taco +.25 makin tacos ])    end +  def test_get_date_without_ident +    assert_nil get_date(%w[ yesterday +2 no task ]) +  end + +  def test_get_date_with_ident +    assert_equal Chronic.parse('2018-01-15'), get_date(%w[ january 15 2018 @taco +.30 makin tacos ]) +  end +    def test_time2float_decimal      assert_equal 2.5, time2float("2.5")    end | 
