[Bug:trunk] behavior change of some methods of Date between 1.8 and 1.9

e$B$U$J$P$5$se(B
e$B1sF#$G$9!#e(B

rubyspec e$B$,e(B Date
e$B$K4X$9$kF0:n$N0c$$$r8+$D$1$^$/$C$F$/$l$k$s$G$9$,!"e(B
Date e$B$NCN<1$,$J$/$F%P%0$+$I$&$+H=CG$G$-$^$;$s!#e(B
e$B$9$_$^$;$s$,0J2<$NF0:n$N0c$$$r%A%’%C%/[email protected]$1$^$9$G$7$g$&$+!#e(B

ruby18 e$B$O$9$Y$Fe(B ruby 1.8.8dev (2010-01-26 revision 26430)
[i686-linux] e$B$G!"e(B
ruby19 e$B$O$9$Y$Fe(B ruby 1.9.2dev (2010-01-28 trunk 26458)
[i686-linux] e$B$G$9!#e(B
ruby-1.9.1-p378

  1. Date.valid_commercial? e$B$NJV$9CM$N??56$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
    nil

$ ruby19 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
true

  1. Date.ordinal e$B$NHO0O$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.ordinal(1582, 287).day’
    /home/mame/work/ruby18/local/lib/ruby/1.8/date.rb:732:in `ordinal’:
    invalid date (ArgumentError)
    from -e:1

$ ruby19 -rdate -e ‘p Date.ordinal(1582, 287).day’
24

  1. Date.ordinal e$B$NHO0O$,JQ$o$C$?!)e(B (e$B$=$Ne(B 2)
    $ ruby18 -rdate -e ‘p Date.ordinal(1582, 288).day’
    15
    $ ruby19 -rdate -e ‘p Date.ordinal(1582, 288).day’
    25

  2. Date.valid_ordinal? e$B$NHO0O$,JQ$o$C$?!)e(B (e$B$=$Ne(B 3)
    $ ruby18 -rdate -e ‘p Date.valid_ordinal?(1582, 287)’
    nil

$ ruby19 -rdate -e ‘p Date.valid_ordinal?(1582, 287)’
true

http://github.com/rubyspec/rubyspec/blob/master/library/date/commercial_spec.rb
http://github.com/rubyspec/rubyspec/blob/master/library/date/ordinal_spec.rb

  1. Date.valid_commercial? e$B$NJV$9CM$N??56$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
    nil

$ ruby19 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
true

e$B$O$$!#e(B

  1. Date.ordinal e$B$NHO0O$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.ordinal(1582, 287).day’
    /home/mame/work/ruby18/local/lib/ruby/1.8/date.rb:732:in `ordinal’:
    invalid date (ArgumentError)
    from -e:1

$ ruby19 -rdate -e ‘p Date.ordinal(1582, 287).day’
24

e$B$O$$!#A0$N%a!<%k$G=q$$$?$N$HF1$8$3$H$G$9!#e(B

$ ./ruby -I lib sample/cal.rb -c it -j 10 1582 # 1.8
October 1582
S M Tu W Th F S
274 275 276 277 288 289
290 291 292 293 294 295 296
297 298 299 300 301 302 303
304

$ ./ruby -I lib sample/cal.rb -c it -j 10 1582 # 1.9
October 1582
S M Tu W Th F S
274 275 276 277 278 279
280 281 282 283 284 285 286
287 288 289 290 291 292 293
294

  1. Date.ordinal e$B$NHO0O$,JQ$o$C$?!)e(B (e$B$=$Ne(B 2)
    $ ruby18 -rdate -e ‘p Date.ordinal(1582, 288).day’
    15
    $ ruby19 -rdate -e ‘p Date.ordinal(1582, 288).day’
    25

e$B$O$$!#e(B

$ ./ruby -I lib sample/cal.rb -c it 10 1582 # 1.8
October 1582
S M Tu W Th F S
1 2 3 4 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

$ ./ruby -I lib sample/cal.rb -c it 10 1582 # 1.9
October 1582
S M Tu W Th F S
1 2 3 4 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

  1. Date.valid_ordinal? e$B$NHO0O$,JQ$o$C$?!)e(B (e$B$=$Ne(B 3)
    $ ruby18 -rdate -e ‘p Date.valid_ordinal?(1582, 287)’
    nil

$ ruby19 -rdate -e ‘p Date.valid_ordinal?(1582, 287)’
true

e$B$O$$!#e(B

e$B%A%1%C%He(B #2676 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BRejectede$B$KJQ99e(B
ruby -v ruby 1.9.2dev (2010-01-28 trunk 26458)
[i686-linux]e$B$K%;%C%He(B

e$B1sF#$G$9!#e(B

e$B$*JV;v$"$j$,$H$&$4$6$$$^$9!#e(B

2010e$BG/e(B1e$B7ne(B28e$BF|e(B22:50 Tadayoshi F. [email protected]:

  1. Date.valid_commercial? e$B$NJV$9CM$N??56$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
    nil

$ ruby19 -rdate -e ‘p Date.valid_commercial?(1582, 41, 4)’
true

e$B$O$$!#e(B

e$B$o$+$j$^$7$?!#e(B
e$B3NG’$G$9$,!"e(B1.8 [email protected]$He(B 1582-10-04 e$B0JA0$Ne(B commercial date
e$B$O07$($J$$e(B
(1581 e$BG/0JA0$b4^$a$Fe(B) e$B$H$$$&$3$H$G$$$$$G$7$g$&$+!#e(B

  1. Date.ordinal e$B$NHO0O$,JQ$o$C$?!)e(B
    $ ruby18 -rdate -e ‘p Date.ordinal(1582, 287).day’
    /home/mame/work/ruby18/local/lib/ruby/1.8/date.rb:732:in `ordinal’:
    invalid date (ArgumentError)
    from -e:1

$ ruby19 -rdate -e ‘p Date.ordinal(1582, 287).day’
24

e$B$O$$!#A0$N%a!<%k$G=q$$$?$N$HF1$8$3$H$G$9!#e(B

e$BB>$b$o$+$C$?$H;W$$$^$9!#$"$j$,$H$&$4$6$$$^$9!#e(B

e$B$o$+$C$?$H$$$$$D$D=q$/$N$K6lO+$7$?%Q%C%Ae(B:

diff --git a/library/date/commercial_spec.rb
b/library/date/commercial_spec.rb
index c960ed7…9367470 100644
— a/library/date/commercial_spec.rb
+++ b/library/date/commercial_spec.rb
@@ -10,20 +10,65 @@ end

describe “Date#valid_commercial?” do

  • it “should be able to determine if the date is a valid commercial
    date” do
  • Date.valid_commercial?(1582, 41, 4).should == nil
  • Date.valid_commercial?(1582, 41, 5).should == Date.civil(1582, 10,
    15).jd
  • valid_commercial? can’t handle dates before the Gregorian

calendar

  • Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == nil
  • Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should ==
    Date.civil(1752, 9, 14, Date::ENGLAND).jd
  • ruby_version_is “” … “1.9” do
  • it “should be able to determine if the date is a valid commercial
    date” do
  •  # October 1582
    
  •  #      M Tu  W Th  F Sa Su
    
  •  # 41:  -  -  -  -  5  6  7
    
  •  # 42:  1  2  3  4  5  6  7
    
  •  # 43:  1  2  3  4  5  6  7
    
  •  # 44:  1
    
  •  Date.valid_commercial?(1582, 41, 4).should == nil
    
  •  Date.valid_commercial?(1582, 41, 5).should == Date.civil(1582, 
    

10, 15).jd

  •  # valid_commercial? can't handle dates before the Gregorian 
    

calendar

  •  Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == nil
    
  •  Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == 
    

Date.civil(1752, 9, 14, Date::ENGLAND).jd

  • end
  • it “should be able to handle negative week and day numbers” do
  •  # October 1582
    
  •  #       M Tu  W Th  F Sa Su
    
  •  # -12:  -  -  -  - -3 -2 -1
    
  •  # -11: -7 -6 -5 -4 -3 -2 -1
    
  •  # -10: -7 -6 -5 -4 -3 -2 -1
    
  •  #  -9: -7
    
  •  Date.valid_commercial?(1582, -12, -4).should == nil
    
  •  Date.valid_commercial?(1582, -12, -3).should == Date.civil(1582, 
    

10, 15).jd
+

  •  Date.valid_commercial?(2007, -44, -2).should == Date.civil(2007, 
    

3, 3).jd

  •  Date.valid_commercial?(2008, -44, -2).should == Date.civil(2008, 
    

3, 1).jd

  • end
    end
  • it “should be able to handle negative week and day numbers” do
  • Date.valid_commercial?(1582, -12, -4).should == nil
  • Date.valid_commercial?(1582, -12, -3).should == Date.civil(1582,
    10, 15).jd
  • Date.valid_commercial?(2007, -44, -2).should == Date.civil(2007, 3,
    3).jd
  • Date.valid_commercial?(2008, -44, -2).should == Date.civil(2008, 3,
    1).jd
  • ruby_version_is “1.9” do
  • it “should be able to determine if the date is a valid commercial
    date” do
  •  # October 1582
    
  •  #      M Tu  W Th  F Sa Su
    
  •  # 39   1  2  3  4  5  6  7
    
  •  # 40:  1  2  3  4  5  6  7
    
  •  # 41:  1  2  3  4  5  6  7
    
  •  # 42:  1
    
  •  Date.valid_commercial?(1582, 39, 4).should == true
    
  •  Date.valid_commercial?(1582, 39, 5).should == true
    
  •  Date.valid_commercial?(1582, 41, 4).should == true
    
  •  Date.valid_commercial?(1582, 41, 5).should == true
    
  •  Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true
    
  •  Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true
    
  • end
  • it “should be able to handle negative week and day numbers” do
  •  # October 1582
    
  •  #       M Tu  W Th  F Sa Su
    
  •  # -12: -7 -6 -5 -4 -3 -2 -1
    
  •  # -11: -7 -6 -5 -4 -3 -2 -1
    
  •  # -10: -7 -6 -5 -4 -3 -2 -1
    
  •  #  -9: -7
    
  •  Date.valid_commercial?(1582, -12, -4).should == true
    
  •  Date.valid_commercial?(1582, -12, -3).should == true
    
  •  Date.valid_commercial?(2007, -44, -2).should == true
    
  •  Date.valid_commercial?(2008, -44, -2).should == true
    
  • end
    end

end
diff --git a/library/date/ordinal_spec.rb b/library/date/ordinal_spec.rb
index 2169d8b…46cefc7 100644
— a/library/date/ordinal_spec.rb
+++ b/library/date/ordinal_spec.rb
@@ -4,26 +4,98 @@ require File.dirname(FILE) + ‘/shared/commercial’

describe “Date#ordinal” do

  • it “should be able to construct a Date object from an ordinal date”
    do
  • lambda { Date.ordinal(1582, 287) }.should
    raise_error(ArgumentError)
  • Date.ordinal(1582, 288).should == Date.civil(1582, 10, 15)
  • Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582,
    10, 14, Date::ENGLAND)
  • ruby_version_is “” … “1.9” do
  • it “should be able to construct a Date object from an ordinal date”
    do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     274 275 276 277 288 289
    
  •  # 290 291 292 293 294 295 296
    
  •  # 297 298 299 300 301 302 303
    
  •  # 304
    
  •  Date.ordinal(1582, 274).should == Date.civil(1582, 10,  1)
    
  •  Date.ordinal(1582, 277).should == Date.civil(1582, 10,  4)
    
  •  lambda { Date.ordinal(1582, 278) }.should 
    

raise_error(ArgumentError)

  •  lambda { Date.ordinal(1582, 287) }.should 
    

raise_error(ArgumentError)

  •  Date.ordinal(1582, 288).should == Date.civil(1582, 10, 15)
    
  •  Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 
    

10, 14, Date::ENGLAND)

  • end
  • end
  • ruby_version_is “1.9” do
  • it “should be able to construct a Date object from an ordinal date”
    do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     274 275 276 277 278 279
    
  •  # 280 281 282 283 284 285 286
    
  •  # 287 288 289 290 291 292 293
    
  •  # 294
    
  •  Date.ordinal(1582, 274).should == Date.civil(1582, 10,  1)
    
  •  Date.ordinal(1582, 277).should == Date.civil(1582, 10,  4)
    
  •  Date.ordinal(1582, 278).should == Date.civil(1582, 10, 15)
    
  •  Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 
    

10, 14, Date::ENGLAND)

  • end
    end

end

describe “Date#valid_ordinal?” do

  • it “should be able to determine if the date is a valid ordinal date”
    do
  • Date.valid_ordinal?(1582, 287).should == nil
  • Date.valid_ordinal?(1582, 288).should == Date.civil(1582, 10,
    15).jd
  • Date.valid_ordinal?(1582, 287, Date::ENGLAND).should_not == nil
  • Date.valid_ordinal?(1582, 287, Date::ENGLAND).should ==
    Date.civil(1582, 10, 14, Date::ENGLAND).jd
  • ruby_version_is “” … “1.9” do
  • it “should be able to determine if the date is a valid ordinal
    date” do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     274 275 276 277 278 279
    
  •  # 280 281 282 283 284 285 286
    
  •  # 287 288 289 290 291 292 293
    
  •  # 294
    
  •  Date.valid_ordinal?(1582, 277).should == Date.civil(1582, 10, 
    

4).jd

  •  Date.valid_ordinal?(1582, 278).should == nil
    
  •  Date.valid_ordinal?(1582, 287).should == nil
    
  •  Date.valid_ordinal?(1582, 288).should == Date.civil(1582, 10, 
    

15).jd

  •  Date.valid_ordinal?(1582, 287, Date::ENGLAND).should_not == nil
    
  •  Date.valid_ordinal?(1582, 287, Date::ENGLAND).should == 
    

Date.civil(1582, 10, 14, Date::ENGLAND).jd

  • end
  • it “should be able to handle negative day numbers” do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     -92 -91 -90 -89 -78 -77
    
  •  # -76 -75 -74 -73 -72 -71 -70
    
  •  # -69 -68 -67 -66 -65 -64 -63
    
  •  # -62
    
  •  Date.valid_ordinal?(1582, -89).should == Date.civil(1582, 10, 
    

4).jd

  •  Date.valid_ordinal?(1582, -88).should == nil
    
  •  Date.valid_ordinal?(1582, -79).should == nil
    
  •  Date.valid_ordinal?(1582, -78).should == Date.civil(1582, 10, 
    

15).jd

  •  Date.valid_ordinal?(2007, -100).should == 
    

Date.valid_ordinal?(2007, 266)

  • end
    end
  • it “should be able to handle negative day numbers” do
  • Date.valid_ordinal?(1582, -79).should == nil
  • Date.valid_ordinal?(2007, -100).should == Date.valid_ordinal?(2007,
  • ruby_version_is “1.9” do
  • it “should be able to determine if the date is a valid ordinal
    date” do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     274 275 276 277 278 279
    
  •  # 280 281 282 283 284 285 286
    
  •  # 287 288 289 290 291 292 293
    
  •  # 294
    
  •  Date.valid_ordinal?(1582, 277).should == true
    
  •  Date.valid_ordinal?(1582, 278).should == true
    
  •  Date.valid_ordinal?(1582, 287).should == true
    
  •  Date.valid_ordinal?(1582, 288).should == true
    
  • end
  • it “should be able to handle negative day numbers” do
  •  # October 1582
    
  •  #   S   M  Tu   W  Th   F   S
    
  •  #     -82 -81 -80 -79 -78 -77
    
  •  # -76 -75 -74 -73 -72 -71 -70
    
  •  # -69 -68 -67 -66 -65 -64 -63
    
  •  # -62
    
  •  Date.valid_ordinal?(1582, -79).should == true
    
  •  Date.valid_ordinal?(1582, -78).should == true
    
  •  Date.valid_ordinal?(2007, -100).should == true
    
  • end
    end

end


Yusuke ENDOH [email protected]

http://redmine.ruby-lang.org/issues/show/2676

e$B3NG’$G$9$,!"e(B1.8 [email protected]$He(B 1582-10-04 e$B0JA0$Ne(B commercial date e$B$O07$($J$$e(B
(1581 e$BG/0JA0$b4^$a$Fe(B) e$B$H$$$&$3$H$G$$$$$G$7$g$&$+!#e(B

e$B$H$$$&$h$j!"%0%l%4%j%*Nq$G$7$+$D$+$($J$$$h$&$K$7$F$$$^$7$?!#@Z$jBX$($re(B
e$B4^$`G/$G$b!"$"$/$^$G%0%l%4%j%Nq$G4Dj$7$?>l9g$N$_$r9M$($k$H$$$&$3$H$G!#e(B

Date.commercial(2,1,1,Date::GREGORIAN).to_s #=> “0001-12-31”

1.9 e$B$G$O!"<B:]$NF|?t$r4pK$K7W;;$9$k$N$G!"$=$&$$$&$3$H$O$J$$$G$9!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs