Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix two issues with month command

The month command didn't previously work in December.  It didn't handle
the logic to understand that January (month 1) follows December (month
12)

Also it's not necessary to call Time#to_date in the month command.  This
method is private in ruby 1.8.6.  Removing this call provides some
additional level of compatibility running under 1.8.6.
  • Loading branch information...
commit 9b744a4366a9f3196e5f5700db45af0b32d1531f 1 parent a3b0bf1
Sam Goldstein authored
Showing with 43 additions and 2 deletions.
  1. +7 −2 lib/timetrap/cli.rb
  2. +36 −0 spec/timetrap_spec.rb
View
9 lib/timetrap/cli.rb
@@ -375,9 +375,14 @@ def week
end
def month
- d = Chronic.parse( "last #{args['-s'] || Date.today.strftime("%B")}" ).to_date
+ d = Chronic.parse( "last #{args['-s'] || Date.today.strftime("%B")}" )
+
beginning_of_month = Date.new( d.year, d.month )
- end_of_month = Date.new( d.year, d.month+1 ) - 1
+ end_of_month = if d.month == 12 # handle edgecase
+ Date.new( d.year + 1, 1) - 1
+ else
+ Date.new( d.year, d.month+1 ) - 1
+ end
args['-s'] = beginning_of_month.to_s
args['-e'] = end_of_month.to_s
display
View
36 spec/timetrap_spec.rb
@@ -599,6 +599,42 @@ def output
end
end
+ describe "month" do
+ it "should display all entries for the month" do
+ create_entry(
+ :start => Time.new(2012, 2, 5, 1, 2, 3),
+ :end => Time.new(2012, 2, 5, 2, 2, 3),
+ )
+ create_entry(
+ :start => Time.new(2012, 2, 6, 1, 2, 3),
+ :end => Time.new(2012, 2, 6, 2, 2, 3),
+ )
+ create_entry(
+ :start => Time.new(2012, 1, 5, 1, 2, 3),
+ :end => Time.new(2012, 1, 5, 2, 2, 3),
+ )
+
+ Date.should_receive(:today).and_return(Date.new(2012, 2, 5))
+ invoke "month"
+
+ $stdout.string.should include 'Feb 05, 2012'
+ $stdout.string.should include 'Feb 06, 2012'
+ $stdout.string.should_not include 'Jan'
+ end
+
+ it "should work in December" do
+ create_entry(
+ :start => Time.new(2012, 12, 5, 1, 2, 3),
+ :end => Time.new(2012, 12, 5, 2, 2, 3),
+ )
+
+ Date.should_receive(:today).and_return(Date.new(2012, 12, 5))
+ invoke "month"
+
+ $stdout.string.should include 'Wed Dec 05, 2012 01:02:03 - 02:02:03'
+ end
+ end
+
describe "kill" do
it "should give me a chance not to fuck up" do
entry = create_entry
Please sign in to comment.
Something went wrong with that request. Please try again.