Skip to content

Commit

Permalink
Month: handle edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
igneus committed Oct 6, 2019
1 parent c91aaef commit d872f42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/calrom/date_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def to_s

class Month < DateRange
def initialize(year, month)
super Date.new(year, month, 1), Date.new(year, month + 1, 1) - 1
next_month_beginning =
if month == 12
Date.new(year + 1, 1, 1)
else
Date.new(year, month + 1, 1)
end
super Date.new(year, month, 1), next_month_beginning - 1
end

def to_s
Expand Down
4 changes: 0 additions & 4 deletions spec/calrom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
it "has a version number" do
expect(Calrom::VERSION).not_to be nil
end

it "does something useful" do
expect(false).to eq(true)
end
end
18 changes: 18 additions & 0 deletions spec/date_range_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'

describe 'date ranges' do
describe Calrom::Month do
1.upto(12) do |i|
it "supports month #{i}" do
described_class.new(2000, i)
end

it "yields Dates of the given year and month #{i}" do
described_class.new(2000, i).each do |date|
expect(date.year).to be 2000
expect(date.month).to be i
end
end
end
end
end

0 comments on commit d872f42

Please sign in to comment.