timetrap 1.7.7 → 1.7.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 7
4
- :patch: 7
4
+ :patch: 8
@@ -63,7 +63,11 @@ module Timetrap
63
63
  end
64
64
 
65
65
  def format_seconds secs
66
- "%2s:%02d:%02d" % [secs/3600, (secs%3600)/60, secs%60]
66
+ negative = secs < 0
67
+ secs = secs.abs
68
+ formatted = "%2s:%02d:%02d" % [secs/3600, (secs%3600)/60, secs%60]
69
+ formatted = "-#{formatted}" if negative
70
+ formatted
67
71
  end
68
72
  alias :format_duration :format_seconds
69
73
 
@@ -18,7 +18,7 @@ module Timetrap
18
18
  end
19
19
 
20
20
  def end= time
21
- self[:end]= Timer.process_time(time)
21
+ self[:end]= Timer.process_time(time, self[:start])
22
22
  end
23
23
 
24
24
  def start
@@ -8,13 +8,13 @@ module Timetrap
8
8
 
9
9
  extend self
10
10
 
11
- def process_time(time)
11
+ def process_time(time, now = Time.now)
12
12
  case time
13
13
  when Time
14
14
  time
15
15
  when String
16
16
  chronic = begin
17
- Chronic.parse(time)
17
+ Chronic.parse(time, :now => now)
18
18
  rescue => e
19
19
  warn "#{e.class} in Chronic gem parsing time. Falling back to Time.parse"
20
20
  end
@@ -898,6 +898,20 @@ END:VCALENDAR
898
898
 
899
899
  end
900
900
 
901
+ describe Timetrap::Helpers do
902
+ before do
903
+ @helper = Object.new
904
+ @helper.extend Timetrap::Helpers
905
+ end
906
+ it "should correctly format positive durations" do
907
+ @helper.format_duration(1234).should == " 0:20:34"
908
+ end
909
+
910
+ it "should correctly format negative durations" do
911
+ @helper.format_duration(-1234).should == "- 0:20:34"
912
+ end
913
+ end
914
+
901
915
 
902
916
  describe Timetrap::Entry do
903
917
 
@@ -999,6 +1013,17 @@ END:VCALENDAR
999
1013
  @entry.end.should == Chronic.parse("tomorrow 1pm")
1000
1014
  end
1001
1015
  end
1016
+
1017
+ describe "setting the end time" do
1018
+ it "should assume a <24 hour duration" do
1019
+ @entry.start= Time.at(Time.now - 3600) # 1.hour.ago
1020
+ @entry.end = Time.at(Time.now - 300).strftime("%H:%M:%S") # ambiguous 5.minutes.ago
1021
+
1022
+ # should be about 55 minutes duration. Allow for second rollover
1023
+ # within this test.
1024
+ (3299..3301).should === @entry.duration
1025
+ end
1026
+ end
1002
1027
  end
1003
1028
 
1004
1029
  end
data/timetrap.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{timetrap}
8
- s.version = "1.7.7"
8
+ s.version = "1.7.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Goldstein"]
12
- s.date = %q{2011-11-27}
12
+ s.date = %q{2011-12-29}
13
13
  s.default_executable = %q{t}
14
14
  s.description = %q{Command line time tracker}
15
15
  s.email = %q{sgrock@gmail.com}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetrap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 7
10
- version: 1.7.7
9
+ - 8
10
+ version: 1.7.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Goldstein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-27 00:00:00 -08:00
18
+ date: 2011-12-29 00:00:00 -08:00
19
19
  default_executable: t
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency