# \[Bug:trunk\] rubyspec: Date#valid\_civil? should be able to handle negative months and days FAILED

**URL:** <https://www.ruby-forum.com/t/bug-trunk-rubyspec-date-valid-civil-should-be-able-to-handle-negative-months-and-days-failed/182460>\
**Category:** Development\
**Created:** [January 28, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/bug-trunk-rubyspec-date-valid-civil-should-be-able-to-handle-negative-months-and-days-failed/182460 "2010-01-28T13:51:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [January 28, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/bug-trunk-rubyspec-date-valid-civil-should-be-able-to-handle-negative-months-and-days-failed/182460/1 "2010-01-28T13:51:55Z")

</div>

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

e$B$^$:3NG’$G$9$,!"e(Bvalid\_civil? e$B$,e(B jd or nil  
e$B$rJV$9$H$$$&;EMM$+$ie(B  
true or false e$B$rJV$9$h$&$K$J$C$?$N$Oe(B 1.9 e$B$+$ie(B  
(e$B$H$$$&$+e(B Date2  
e$B$+$i!)e(B) e$B$N;EMMJQ99$G$9$h$M!#e(B

e$B$=$NE@$r=$@5$7$?\>e$G!"e(Brubyspec  
e$B$,0J2\<$N5sF0$NJQ2=$r8!=P$7$^$7$?!#e(B

$ ruby18 -v -rdate -e ‘p Date.valid\_civil?(1582, -3, -18)’  
ruby 1.8.8dev (2010-01-26 revision 26430) [i686-linux]  
nil

$ ./ruby -v -rdate -e ‘p Date.valid\_civil?(1582, -3, -18)’  
ruby 1.9.2dev (2010-01-28 trunk 26458) [i686-linux]  
true

$ ruby-1.9.1-p378 -v -rdate -e ‘p Date.valid\_civil?(1582, -3, -18)’  
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]  
true

e$B!Ve(BDate e$B$N7nF|$KIi$NCM$rF~$l$F$bF0$/!W$H$$$&e(B spec  
e$B$,$"$C$F!"e(B  
e$B$=$l$,$&$^$/F0$+$J$/$J$C$F$$$k$h$&$G$9!#e(B

[http://github.com/rubyspec/rubyspec/blob/master/library/date/civil\_spec.rb](http://github.com/rubyspec/rubyspec/blob/master/library/date/civil_spec.rb)

date.rb e$B$Ne(B \_valid\_civil? e$B$N%3%a%s%H$K$h$k$H!“Ii$NCM$G$bF0$/e(B  
e$B$h$&$J$3$H$,=q$+$l$F$$$^$9$N$G!”$3$l$O%P%0$G$7$g$&$+!#e(B

```
# +m+ and +d+ can be negative, in which case they count
# backwards from the end of the year and the end of the
# month respectively.

```

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [January 28, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/bug-trunk-rubyspec-date-valid-civil-should-be-able-to-handle-negative-months-and-days-failed/182460/2 "2010-01-28T14:34:03Z")

</div>

> e$B$^$:3NG’$G$9$,!"e(Bvalid\_civil? e$B$,e(B jd or nil e$B$rJV$9$H$$$&;EMM$+$ie(B  
> true or false e$B$rJV$9$h$&$K$J$C$?$N$Oe(B 1.9 e$B$+$ie(B (e$B$H$$$&$+e(B Date2  
> e$B$+$i!)e(B) e$B$N;EMMJQ99$G$9$h$M!#e(B

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

> e$B$=$NE@$r=$@5$7$?\>e$G!"e(Brubyspec e$B$,0J2\<$N5sF0$NJQ2=$r8!=P$7$^$7$?!#e(B

e$B3"F|$+$i$N?t$($+$?$NJQ99$G$9!#e(B1.8  
e$B$G$O0J2\<$N$h$&$K$J$C$F$$$F!"Ht$s$@$He(B  
e$B$3$m$K$bF|$r3d$jEv$F$i$l$F$$$k$+$N$h$&$K?t$($F$$$^$7$?!#e(B

# October 1582

# S M Tu W Th F S

# -31 -30 -29 -28 -17 -16

# -15 -14 -13 -12 -11 -10 -9

# -8 -7 -6 -5 -4 -3 -2

# -1

1.9 e$B$G$O!"e(B

# October 1582

# S M Tu W Th F S

# -21 -20 -19 -18 -17 -16

# -15 -14 -13 -12 -11 -10 -9

# -8 -7 -6 -5 -4 -3 -2

# -1

e$B$N$h$&$KK\Ev$KB8:\_$9$k$b$N$@$1?t$($k$h$&$K$7$F$$$^$9!#$I$C$A$,@5$7$$$He(B  
e$B$$$&$o$1$G$O$J$$$N$G$9$,!"$3$N$h$&$JNc30E\*$J$H$3$m$G$N5sF0$rA\*Br$7$J$le(B  
e$B$P$J$j$^$;$s!#G/$NF|$N$[$&$N$"$D$+$$$HB7$($k$H$H$b$K!"$3$N$[$&$,ET9g$,e(B  
e$B$h$$$N$G$=$&$7$^$7$?!#e(B

e$B$7$?$,$C$F!"e(B1582e$BG/e(B-3e$B7ne(B-18e$BF|$O!"e(B1.8  
e$B$G$OB8:_$9$k$,!"e(B1.9 e$B$G$OB8:_$7$J$$$He(B  
e$B$$$&$3$H$K$J$j$^$9!#e(B

---

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [January 28, 2010, 3:03pm UTC](https://www.ruby-forum.com/t/bug-trunk-rubyspec-date-valid-civil-should-be-able-to-handle-negative-months-and-days-failed/182460/3 "2010-01-28T15:03:19Z")

</div>

e$B%A%1%C%He(B #2675 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$B$7$?$,$C$F!"e(B1582e$BG/e(B-3e$B7ne(B-18e$BF|$O!"e(B1.8 e$B$G$OB8:_$9$k$,!"e(B1.9 e$B$G$OB8:_$7$J$$$He(B  
> e$B$$$&$3$H$K$J$j$^$9!#e(B

e$B@bL@$"$j$,$H$&$4$6$$$^$9!\*$o$+$j$^$7$?!#e(B  
e$BJ9$+$J$$$HE~Dl$o$+$j$=$&$K$J$+$C$?$G$9!#e(B

e$B$3$N%A%1%C%H$Oe(B reject e$B$7$D$D!"0J2\<$N$h$&$J%Q%C%A$re(B rubyspec  
e$B$Ke(B  
e$BAw$m$&$H;W$$$^$9!#e(B

diff --git a/library/date/civil\_spec.rb b/library/date/civil\_spec.rb  
index e26968c…d169cc2 100644  
— a/library/date/civil\_spec.rb  
+++ b/library/date/civil\_spec.rb  
@@ -10,19 +10,56 @@ end

describe “Date#valid\_civil?” do

- it “should be able to determine if a date is valid” do
- Date.valid\_civil?(1582, 10, 14).should == nil
- Date.valid\_civil?(1582, 10, 15).should == Date.civil(1582, 10,  
15).jd
- Date.valid\_civil?(1582, 10, 14, Date::ENGLAND).should\_not == nil
- Date.valid\_civil?(1582, 10, 14, Date::ENGLAND).should ==  
Date.civil(1582, 10, 14, Date::ENGLAND).jd

- ruby\_version\_is “” … “1.9” do
- it “should be able to determine if a date is valid” do
- 

```
 Date.valid_civil?(1582, 10, 14).should == nil

```

- 

```
 Date.valid_civil?(1582, 10, 15).should == Date.civil(1582, 10, 

```

15).jd

- 

```
 Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should_not == nil

```

- 

```
 Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == 

```

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

- end
- 
- it “should be able to handle negative months and days” do
- 

```
 # October 1582

```

- 

```
 # S M Tu W Th F S

```

- 

```
 # -31 -30 -29 -28 -17 -16

```

- 

```
 # -15 -14 -13 -12 -11 -10 -9

```

- 

```
 # -8 -7 -6 -5 -4 -3 -2

```

- 

```
 # -1

```

- 

```
 Date.valid_civil?(1582, -3, -31).should == Date.civil(1582, 10, 

```

1).jd

- 

```
 Date.valid_civil?(1582, -3, -28).should == Date.civil(1582, 10, 

```

4).jd

- 

```
 Date.valid_civil?(1582, -3, -27).should == nil

```

- 

```
 Date.valid_civil?(1582, -3, -22).should == nil

```

- 

```
 Date.valid_civil?(1582, -3, -21).should == nil

```

- 

```
 Date.valid_civil?(1582, -3, -18).should == nil

```

- 

```
 Date.valid_civil?(1582, -3, -17).should == Date.civil(1582, 10, 

```

15).jd  
+

- 

```
 Date.valid_civil?(2007, -11, -10).should == Date.civil(2007, 2, 

```

19).jd

- 

```
 Date.valid_civil?(2008, -11, -10).should == Date.civil(2008, 2, 

```

20).jd

- end  
end

- 
- it “should be able to handle negative months and days” do
- Date.valid\_civil?(1582, -3, -18).should == nil
- Date.valid\_civil?(1582, -3, -17).should == Date.civil(1582, 10,  
15).jd

- 
- ruby\_version\_is “1.9” do
- it “should be able to determine if a date is valid” do
- 

```
 Date.valid_civil?(1582, 10, 14).should == false

```

- 

```
 Date.valid_civil?(1582, 10, 15).should == true

```

- 

```
 Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == true

```

- end
- 
- it “should be able to handle negative months and days” do
- 

```
 # October 1582

```

- 

```
 # S M Tu W Th F S

```

- 

```
 # -21 -20 -19 -18 -17 -16

```

- 

```
 # -15 -14 -13 -12 -11 -10 -9

```

- 

```
 # -8 -7 -6 -5 -4 -3 -2

```

- 

```
 # -1

```

- 

```
 Date.valid_civil?(1582, -3, -22).should == false

```

- 

```
 Date.valid_civil?(1582, -3, -21).should == true

```

- 

```
 Date.valid_civil?(1582, -3, -18).should == true

```

- 

```
 Date.valid_civil?(1582, -3, -17).should == true

```

- Date.valid\_civil?(2007, -11, -10).should == Date.civil(2007, 2,  
19).jd
- Date.valid\_civil?(2008, -11, -10).should == Date.civil(2008, 2,  
20).jd

- 

```
 Date.valid_civil?(2007, -11, -10).should == true

```

- 

```
 Date.valid_civil?(2008, -11, -10).should == true

```

- end  
end

end

## – Yusuke E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[http://redmine.ruby-lang.org/issues/show/2675](http://redmine.ruby-lang.org/issues/show/2675)
