Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 26d0b20ca324
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a8ee690599a2
Choose a head ref
  • 3 commits
  • 7 files changed
  • 2 contributors

Commits on Jul 21, 2015

  1. Add specs for Date#{<<,prev_year,next_year} around calendar reforms.

    * See #2867.
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    ec80a32 View commit details
  2. [#2867] modified Date#>> to take calendar reforms under consideration

    - added tests for next month with calendar reform
    - uses solution provided in #1769 comments
    - also fixes issues #1769
    Ranjeet Singh authored and eregon committed Jul 21, 2015
    Copy the full SHA
    40e9140 View commit details
  3. Copy the full SHA
    a8ee690 View commit details
11 changes: 9 additions & 2 deletions lib/ruby/1.9/date.rb
Original file line number Diff line number Diff line change
@@ -1458,7 +1458,14 @@ def next() next_day end
# of the returned Date will be the last day of the target month.
def >> (n)
n = n.to_int rescue raise(TypeError, "n must be a Fixnum")
self.class.new!(@dt.plusMonths(n), @of, @sg, @sub_millis)
y, m = ((year * 12) + (mon - 1) + n).divmod(12)
m, = (m + 1).divmod(1)
d = mday
until cd = _valid_civil?(y, m, d, start)
d -= 1
raise ArgumentError, "invalid date" unless d > 0
end
self + (cd - jd)
end

# Return a new Date object that is +n+ months earlier than
@@ -1473,7 +1480,7 @@ def next_month(n=1) self >> n end
def prev_month(n=1) self << n end

def next_year(n=1)
self.class.new!(@dt.plusYears(n.to_i), @of, @sg, @sub_millis)
self >> (n * 12)
end

def prev_year(n=1)
8 changes: 8 additions & 0 deletions spec/ruby/library/date/add_month_spec.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,14 @@
d.should == Date.civil(2008, 4, 30)
end

it "returns the day of the reform if date falls within calendar reform" do
calendar_reform_italy = Date.new(1582, 10, 4)
d1 = Date.new(1582, 9, 9) >> 1
d2 = Date.new(1582, 9, 10) >> 1
d1.should == calendar_reform_italy
d2.should == calendar_reform_italy
end

it "raise a TypeError when passed a Symbol" do
lambda { Date.civil(2007,2,27) >> :hello }.should raise_error(TypeError)
end
12 changes: 12 additions & 0 deletions spec/ruby/library/date/next_year_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'

describe "Date#next_year" do
it "returns the day of the reform if date falls within calendar reform" do
calendar_reform_italy = Date.new(1582, 10, 4)
d1 = Date.new(1581, 10, 9).next_year
d2 = Date.new(1581, 10, 10).next_year
d1.should == calendar_reform_italy
d2.should == calendar_reform_italy
end
end
12 changes: 12 additions & 0 deletions spec/ruby/library/date/prev_year_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'

describe "Date#prev_year" do
it "returns the day of the reform if date falls within calendar reform" do
calendar_reform_italy = Date.new(1582, 10, 4)
d1 = Date.new(1583, 10, 9).prev_year
d2 = Date.new(1583, 10, 10).prev_year
d1.should == calendar_reform_italy
d2.should == calendar_reform_italy
end
end
1 change: 1 addition & 0 deletions spec/tags/1.8/ruby/library/date/add_month_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Date#>> returns the day of the reform if date falls within calendar reform
1 change: 1 addition & 0 deletions spec/tags/1.8/ruby/library/date/next_year_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Date#next_year returns the day of the reform if date falls within calendar reform
1 change: 1 addition & 0 deletions spec/tags/1.8/ruby/library/date/prev_year_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Date#prev_year returns the day of the reform if date falls within calendar reform