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]:
- 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 e$B$@$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
- 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
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
+
3, 3).jd
3, 1).jd
- 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)
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
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, 266)
- 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
http://redmine.ruby-lang.org/issues/show/2676