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: dd4b72efeab2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 45154e9abd43
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Jul 21, 2015

  1. [#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
    3b83d09 View commit details
  2. 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
    d2a4cb2 View commit details

Commits on Jul 23, 2015

  1. Merge pull request #3157 from eregon/date_next_year_difference

    Date next year difference
    eregon committed Jul 23, 2015
    Copy the full SHA
    45154e9 View commit details
Showing with 41 additions and 2 deletions.
  1. +9 −2 lib/ruby/stdlib/date.rb
  2. +8 −0 spec/ruby/library/date/add_month_spec.rb
  3. +12 −0 spec/ruby/library/date/next_year_spec.rb
  4. +12 −0 spec/ruby/library/date/prev_year_spec.rb
11 changes: 9 additions & 2 deletions lib/ruby/stdlib/date.rb
Original file line number Diff line number Diff line change
@@ -1454,7 +1454,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
@@ -1469,7 +1476,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