home_run 0.9.0-x86-mswin32-60 → 0.9.1-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Date limits: " do
4
+ before do
5
+ @d1 = Date.jd(Date::JULIAN - 1)
6
+ @d2 = Date.jd(Date::GREGORIAN + 1)
7
+ end
8
+
9
+ it "#+ and #- should raise RangeError for dates that are too large or small" do
10
+ proc{Date.jd(@d1.jd) + 1}.should raise_error(RangeError)
11
+ proc{Date.jd(@d2.jd) - 1}.should raise_error(RangeError)
12
+ end
13
+
14
+ it "#<< and #>> should raise RangeError for dates that are too large or small" do
15
+ proc{Date.jd(@d1.jd) >> 1}.should raise_error(RangeError)
16
+ proc{Date.jd(@d2.jd) << 1}.should raise_error(RangeError)
17
+ end
18
+
19
+ ruby_version_is "1.9" do
20
+ it "#next_year and #prev_year should raise RangeError for dates that are too large or small" do
21
+ proc{Date.jd(@d1.jd).next_year}.should raise_error(RangeError)
22
+ proc{Date.jd(@d2.jd).prev_year}.should raise_error(RangeError)
23
+ end
24
+ end
25
+
26
+ it ".jd should raise RangeError for dates that are too large or small" do
27
+ proc{Date.jd(@d1.jd + 1)}.should raise_error(RangeError)
28
+ proc{Date.jd(@d2.jd - 1)}.should raise_error(RangeError)
29
+ end
30
+
31
+ it ".jd should not raise for dates that are not too large or small" do
32
+ proc{Date.jd(@d1.jd)}.should_not raise_error
33
+ proc{Date.jd(@d2.jd)}.should_not raise_error
34
+ end
35
+
36
+ it ".new! should raise RangeError for dates that are too large or small" do
37
+ proc{Date.new!(@d1.jd + 1)}.should raise_error(RangeError)
38
+ proc{Date.new!(@d2.jd - 1)}.should raise_error(RangeError)
39
+ end
40
+
41
+ it ".new! should not raise for dates that are not too large or small" do
42
+ proc{Date.new!(@d1.jd)}.should_not raise_error
43
+ proc{Date.new!(@d2.jd)}.should_not raise_error
44
+ end
45
+
46
+ it ".civil should raise RangeError for dates that are too large or small" do
47
+ proc{Date.civil(@d1.year, @d1.month, @d1.day + 1)}.should raise_error(RangeError)
48
+ proc{Date.civil(@d2.year, @d2.month, @d2.day - 1)}.should raise_error(RangeError)
49
+ end
50
+
51
+ it ".civil should not raise for dates that are not too large or small" do
52
+ proc{Date.civil(@d1.year, @d1.month, @d1.day)}.should_not raise_error
53
+ proc{Date.civil(@d2.year, @d2.month, @d2.day)}.should_not raise_error
54
+ end
55
+
56
+ it ".civil should correctly convert dates within limits to JD" do
57
+ Date.civil(@d1.year, @d1.month, @d1.day).jd.should == @d1.jd
58
+ Date.civil(@d2.year, @d2.month, @d2.day).jd.should == @d2.jd
59
+ end
60
+
61
+ it ".commercial should raise RangeError for dates that are too large or small" do
62
+ proc{Date.commercial(@d1.cwyear, @d1.cwday == 6 ? @d1.cweek + 1 : @d1.cweek, @d1.cwday == 6 ? 1 : @d1.cwday + 1)}.should raise_error(RangeError)
63
+ proc{Date.commercial(@d2.cwyear, @d2.cwday == 1 ? @d2.cweek - 1 : @d2.cweek, @d2.cwday == 1 ? 7 : @d2.cwday - 1)}.should raise_error(RangeError)
64
+ end
65
+
66
+ it ".commercial should not raise for dates that are not too large or small" do
67
+ proc{Date.commercial(@d1.cwyear, @d1.cweek, @d1.cwday)}.should_not raise_error
68
+ proc{Date.commercial(@d2.cwyear, @d2.cweek, @d2.cwday)}.should_not raise_error
69
+ end
70
+
71
+ it ".commercial should correctly convert dates within limits to JD" do
72
+ Date.commercial(@d1.cwyear, @d1.cweek, @d1.cwday).jd.should == @d1.jd
73
+ Date.commercial(@d2.cwyear, @d2.cweek, @d2.cwday).jd.should == @d2.jd
74
+ end
75
+
76
+ it ".ordinal should raise RangeError for dates that are too large or small" do
77
+ proc{Date.ordinal(@d1.year, @d1.yday + 1)}.should raise_error(RangeError)
78
+ proc{Date.ordinal(@d2.year, @d2.yday - 1)}.should raise_error(RangeError)
79
+ end
80
+
81
+ it ".ordinal should not raise for dates that are not too large or small" do
82
+ proc{Date.ordinal(@d1.year, @d1.yday)}.should_not raise_error
83
+ proc{Date.ordinal(@d2.year, @d2.yday)}.should_not raise_error
84
+ end
85
+
86
+ it ".ordinal should correctly convert dates within limits to JD" do
87
+ Date.ordinal(@d1.year, @d1.yday).jd.should == @d1.jd
88
+ Date.ordinal(@d2.year, @d2.yday).jd.should == @d2.jd
89
+ end
90
+
91
+ it ".parse should raise RangeError for civil dates that are too large or small" do
92
+ proc{Date.parse("#{@d1.year}-#{@d1.month}-#{@d1.day+1}")}.should raise_error(RangeError)
93
+ proc{Date.parse("#{@d2.year}-#{@d2.month}-#{@d2.day-1}")}.should raise_error(RangeError)
94
+ end
95
+
96
+ it ".parse should not raise for civil dates that are not too large or small" do
97
+ proc{Date.parse("#{@d1.year}-#{@d1.month}-#{@d1.day}")}.should_not raise_error
98
+ proc{Date.parse("#{@d2.year}-#{@d2.month}-#{@d2.day}")}.should_not raise_error
99
+ end
100
+
101
+ it ".parse should correctly convert civil dates within limits to JD" do
102
+ Date.parse("#{@d1.year}-#{@d1.month}-#{@d1.day}").jd.should == @d1.jd
103
+ Date.parse("#{@d2.year}-#{@d2.month}-#{@d2.day}").jd.should == @d2.jd
104
+ end
105
+
106
+ it ".strptime should raise RangeError for civil dates that are too large or small" do
107
+ proc{Date.strptime("#{@d1.year}-#{@d1.month}-#{@d1.day+1}", "%Y-%m-%d")}.should raise_error(RangeError)
108
+ proc{Date.strptime("#{@d2.year}-#{@d2.month}-#{@d2.day-1}", "%Y-%m-%d")}.should raise_error(RangeError)
109
+ end
110
+
111
+ it ".strptime should not raise for civil dates that are not too large or small" do
112
+ proc{Date.strptime("#{@d1.year}-#{@d1.month}-#{@d1.day}", "%Y-%m-%d")}.should_not raise_error
113
+ proc{Date.strptime("#{@d2.year}-#{@d2.month}-#{@d2.day}", "%Y-%m-%d")}.should_not raise_error
114
+ end
115
+
116
+ it ".strptime should correctly convert civil dates within limits to JD" do
117
+ Date.strptime("#{@d1.year}-#{@d1.month}-#{@d1.day}", "%Y-%m-%d").jd.should == @d1.jd
118
+ Date.strptime("#{@d2.year}-#{@d2.month}-#{@d2.day}", "%Y-%m-%d").jd.should == @d2.jd
119
+ end
120
+
121
+ end
@@ -11,11 +11,16 @@ ruby_version_is "" ... "1.9" do
11
11
  Date.zone_to_diff('+08:00').should == 28800
12
12
  Date.zone_to_diff('+08:30').should == 30600
13
13
  Date.zone_to_diff('+08:30:04').should == 30604
14
+ Date.zone_to_diff('-08:00').should == -28800
15
+ Date.zone_to_diff('-08:30').should == -30600
16
+ Date.zone_to_diff('-08:30:04').should == -30604
14
17
  end
15
18
 
16
19
  it "should return the offset for the given numeric time zone with . or ," do
17
20
  Date.zone_to_diff('+08,30').should == 29880
18
21
  Date.zone_to_diff('+08.30').should == 29880
22
+ Date.zone_to_diff('-08,30').should == -29880
23
+ Date.zone_to_diff('-08.30').should == -29880
19
24
  end
20
25
 
21
26
  it "should return the offset for the given numeric time with all digits" do
@@ -73,7 +78,67 @@ describe "Date.parse" do
73
78
  d.should == Date.civil(Date.today.year, Date.today.month, 5)
74
79
  end
75
80
 
81
+ it "can handle BC/BCE in the string as being a negative year" do
82
+ Date.parse("BC 2012-11-10").should == Date.civil(-2011, 11, 10)
83
+ Date.parse("2012-11-10 BCE").should == Date.civil(-2011, 11, 10)
84
+ end
85
+
86
+ it "can handle a leftover DD string as a day if time has been parsed" do
87
+ Date.parse("'09 10:20:30 13").should == Date.civil(2009, 1, 13)
88
+ end
89
+
90
+ it "can handle 'DD as a year" do
91
+ Date.parse("'12").should == Date.civil(2012, 1, 1)
92
+ end
93
+
94
+ it "can handle JIS X 301 format" do
95
+ Date.parse("H22.01.06").should == Date.civil(2010, 1, 6)
96
+ end
97
+
98
+ it "can handle DDDD-MMM-DD VMS format" do
99
+ Date.parse("2012-jan-06").should == Date.civil(2012, 1, 6)
100
+ end
101
+
102
+ it "can handle MMM-DDDD-DD VMS format" do
103
+ Date.parse("jan-2012-06").should == Date.civil(2012, 1, 6)
104
+ end
105
+
106
+ # Less common ISO formats
107
+
108
+ it "can handle DDDD-wDD-D as a commercial week date" do
109
+ Date.parse("2011-w12-6").should == Date.commercial(2011, 12, 6)
110
+ end
111
+
112
+ it "can handle DD-wDD-D as a commercial week date" do
113
+ Date.parse("11-w12-6").should == Date.commercial(2011, 12, 6)
114
+ end
115
+
116
+ it "can handle -wDD-D as a commercial week date in the current year" do
117
+ Date.parse("-w12-6").should == Date.commercial(Time.now.year, 12, 6)
118
+ end
119
+
120
+ it "can handle -w-D as a commercial week date in the current year" do
121
+ Date.parse("-w-6").should == Date.commercial(Time.now.year, 1, 6)
122
+ end
123
+
124
+ it "can handle ---DD as a day in the current month" do
125
+ Date.parse("---06").should == Date.civil(Time.now.year, Time.now.month, 6)
126
+ end
127
+
128
+ it "can handle --DDDD as a month and day in the current year" do
129
+ Date.parse("--1206").should == Date.civil(Time.now.year, 12, 6)
130
+ end
131
+
132
+ it "can handle DDDD-DDD as an ordinal date" do
133
+ Date.parse("2012-106").should == Date.ordinal(2012, 106)
134
+ end
135
+
136
+ it "can handle -DDD as an ordinal day in the current year" do
137
+ Date.parse("blah-106").should == Date.ordinal(Time.now.year, 106)
138
+ end
139
+
76
140
  # Specs using numbers
141
+
77
142
  it "can't handle a single digit" do
78
143
  lambda{ Date.parse("1") }.should raise_error(ArgumentError)
79
144
  end
@@ -283,6 +348,14 @@ describe "Date#parse with ' ' separator" do
283
348
  end
284
349
 
285
350
  it_should_behave_like "date_parse"
351
+
352
+ it "can parse a 'DD mmm BC YYYY' string into a Date object" do
353
+ d = Date.parse("23 feb BC 2008")
354
+ d.year.should == -2007
355
+ d.month.should == 2
356
+ d.day.should == 23
357
+ end
358
+
286
359
  end
287
360
 
288
361
  describe "Date#parse with '/' separator US-style" do
@@ -438,5 +511,86 @@ describe "Date::Format::STYLE" do
438
511
  d.month.should == 1
439
512
  d.day.should == 10
440
513
  end
514
+
515
+ it "Can parse DD/DD/'DD with all three types" do
516
+ Date::Format::STYLE[:slash] = :ymd
517
+ Date.parse("12/11/'10").should == Date.civil(2010, 11, 12)
518
+ Date::Format::STYLE[:slash] = :dmy
519
+ Date.parse("12/11/'10").should == Date.civil(2010, 11, 12)
520
+ Date::Format::STYLE[:slash] = :mdy
521
+ Date.parse("12/11/'10").should == Date.civil(2010, 12, 11)
522
+ end
523
+
524
+ it "Can parse 'DD/DD/DD with all three types" do
525
+ Date::Format::STYLE[:slash] = :ymd
526
+ Date.parse("'12/11/10").should == Date.civil(2012, 11, 10)
527
+ Date::Format::STYLE[:slash] = :dmy
528
+ Date.parse("'12/11/10").should == Date.civil(2012, 11, 10)
529
+ Date::Format::STYLE[:slash] = :mdy
530
+ Date.parse("'12/11/10").should == Date.civil(2012, 11, 10)
531
+ end
532
+
533
+ it "Can parse DD/'DD/DD with all three types" do
534
+ Date::Format::STYLE[:slash] = :ymd
535
+ Date.parse("12/'11/10").should == Date.civil(2011, 10, 12)
536
+ Date::Format::STYLE[:slash] = :dmy
537
+ Date.parse("12/'11/10").should == Date.civil(2011, 12, 10)
538
+ Date::Format::STYLE[:slash] = :mdy
539
+ Date.parse("12/'11/10").should == Date.civil(2011, 12, 10)
540
+ end
541
+
542
+ it "Can parse DD/'DD with all three types" do
543
+ Date::Format::STYLE[:slash] = :ymd
544
+ Date.parse("12/'11").should == Date.civil(2011, 12, 1)
545
+ Date::Format::STYLE[:slash] = :dmy
546
+ Date.parse("12/'11").should == Date.civil(2011, 12, 1)
547
+ Date::Format::STYLE[:slash] = :mdy
548
+ Date.parse("12/'11").should == Date.civil(2011, 12, 1)
549
+ end
550
+
551
+ it "Can parse 'DD/DD with all three types" do
552
+ Date::Format::STYLE[:slash] = :ymd
553
+ Date.parse("'12/11").should == Date.civil(2012, 11, 1)
554
+ Date::Format::STYLE[:slash] = :dmy
555
+ Date.parse("'12/11").should == Date.civil(2012, 11, 1)
556
+ Date::Format::STYLE[:slash] = :mdy
557
+ Date.parse("'12/11").should == Date.civil(2012, 11, 1)
558
+ end
559
+
560
+ it "Can parse 'D/DD with all three types" do
561
+ Date::Format::STYLE[:slash] = :ymd
562
+ Date.parse("'2/11").should == Date.civil(2002, 11, 1)
563
+ Date::Format::STYLE[:slash] = :dmy
564
+ Date.parse("'2/11").should == Date.civil(2002, 11, 1)
565
+ Date::Format::STYLE[:slash] = :mdy
566
+ Date.parse("'2/11").should == Date.civil(2002, 11, 1)
567
+ end
568
+
569
+ it "Can parse DD/DD with all three types" do
570
+ Date::Format::STYLE[:slash] = :ymd
571
+ Date.parse("12/11").should == Date.civil(Time.now.year, 12, 11)
572
+ Date::Format::STYLE[:slash] = :dmy
573
+ Date.parse("12/11").should == Date.civil(Time.now.year, 11, 12)
574
+ Date::Format::STYLE[:slash] = :mdy
575
+ Date.parse("12/11").should == Date.civil(Time.now.year, 12, 11)
576
+ end
577
+
578
+ it "Can parse DDDD/DD as year/month with all three types" do
579
+ Date::Format::STYLE[:slash] = :ymd
580
+ Date.parse("2012/11").should == Date.civil(2012, 11, 1)
581
+ Date::Format::STYLE[:slash] = :dmy
582
+ Date.parse("2012/11").should == Date.civil(2012, 11, 1)
583
+ Date::Format::STYLE[:slash] = :mdy
584
+ Date.parse("2012/11").should == Date.civil(2012, 11, 1)
585
+ end
586
+
587
+ it "Can parse DD/DDDD as month/year with all three types" do
588
+ Date::Format::STYLE[:slash] = :ymd
589
+ Date.parse("11/2012").should == Date.civil(2012, 11, 1)
590
+ Date::Format::STYLE[:slash] = :dmy
591
+ Date.parse("11/2012").should == Date.civil(2012, 11, 1)
592
+ Date::Format::STYLE[:slash] = :mdy
593
+ Date.parse("11/2012").should == Date.civil(2012, 11, 1)
594
+ end
441
595
  end
442
596
 
@@ -5,10 +5,15 @@ ruby_version_is "1.9" do
5
5
  it "._httpdate should parse an HTTP format" do
6
6
  Date._httpdate("Fri, 02 Jan 2009 00:00:00 GMT").should ==
7
7
  {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0, :offset=>0, :zone=>'GMT'}
8
+ Date._httpdate("Friday, 02-Jan-09 00:00:00 GMT").should ==
9
+ {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0, :offset=>0, :zone=>'GMT'}
10
+ Date._httpdate("Fri Jan 2 00:00:00 2009").should ==
11
+ {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0}
8
12
  end
9
13
 
10
14
  it "._iso8601 should parse an ISO8601 format" do
11
15
  Date._iso8601("2009-01-02").should == {:year=>2009, :mon=>1, :mday=>2}
16
+ Date._iso8601("--1002").should == {:mon=>10, :mday=>2}
12
17
  end
13
18
 
14
19
  it "._jisx03010 should parse an JIS X 0301 format" do
@@ -19,11 +24,17 @@ ruby_version_is "1.9" do
19
24
  Date._jisx0301("M06.01.02").should == {:year=>1873, :mon=>1, :mday=>2}
20
25
  Date._jisx0301("1872-01-02").should == {:year=>1872, :mon=>1, :mday=>2}
21
26
  Date._jisx0301("1867-01-02").should == {:year=>1867, :mon=>1, :mday=>2}
27
+
28
+ Date._jisx0301("21.01.02").should == {:year=>2009, :mon=>1, :mday=>2}
22
29
  end
23
30
 
24
31
  it "._rfc2822 should parse an RFC2822 format" do
25
32
  Date._rfc2822("Fri, 2 Jan 2009 00:00:00 +0000").should ==
26
33
  {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0, :offset=>0, :zone=>'+0000'}
34
+ Date._rfc2822("Fri, 2 Jan 09 00:00:00 +0000").should ==
35
+ {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0, :offset=>0, :zone=>'+0000'}
36
+ Date._rfc2822("Fri, 2 Jan 109 00:00:00 +0000").should ==
37
+ {:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>0, :min=>0, :sec=>0, :offset=>0, :zone=>'+0000'}
27
38
  end
28
39
 
29
40
  it "._rfc822 should parse an RFC822 format" do
@@ -2,6 +2,28 @@ require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe "Date#step" do
4
4
 
5
+ ruby_version_is "" ... "1.9" do
6
+ it "should require a block" do
7
+ proc{Date.today.step(Date.today)}.should raise_error(LocalJumpError)
8
+ end
9
+ end
10
+
11
+ ruby_version_is "1.9" do
12
+ it "should return an enumerator without a block" do
13
+ ds = Date.civil(2008, 10, 11)
14
+ de = Date.civil(2008, 9, 29)
15
+ e = de.step(ds)
16
+ e.should be_kind_of(Enumerator)
17
+ count = 0
18
+ e.each do |d|
19
+ d.should <= ds
20
+ d.should >= de
21
+ count += 1
22
+ end.should == de
23
+ count.should == 13
24
+ end
25
+ end
26
+
5
27
  it "should be able to step forward in time" do
6
28
  ds = Date.civil(2008, 10, 11)
7
29
  de = Date.civil(2008, 9, 29)
@@ -84,9 +84,15 @@ describe "Date#strptime" do
84
84
  Date.strptime(" 6", "%e").should == Date.civil(d.year, d.month, 6)
85
85
  end
86
86
 
87
- it "parses a commercial year with leading zeroes" do
87
+ it "parses a commercial year" do
88
88
  Date.strptime("2000", "%G").should == Date.civil(2000, 1, 3)
89
89
  Date.strptime("2002", "%G").should == Date.civil(2001, 12, 31)
90
+ Date.strptime("20000", "%G").should == Date.civil(20000, 1, 3)
91
+ end
92
+
93
+ it "parses a commercial year with trailing numbers" do
94
+ Date.strptime("20000", "%G0").should == Date.civil(2000, 1, 3)
95
+ Date.strptime("20023", "%G%u").should == Date.civil(2002, 1, 2)
90
96
  end
91
97
 
92
98
  it "parses a commercial year with only two digits" do
@@ -152,8 +158,15 @@ describe "Date#strptime" do
152
158
  Date.strptime("2007 4", "%Y %w").should == Date.civil(2007, 1, 4)
153
159
  end
154
160
 
155
- it "parses a year in YYYY format" do
161
+ it "parses a full year " do
156
162
  Date.strptime("2007", "%Y").should == Date.civil(2007, 1, 1)
163
+ Date.strptime("200", "%Y").should == Date.civil(200, 1, 1)
164
+ Date.strptime("20000", "%Y").should == Date.civil(20000, 1, 1)
165
+ end
166
+
167
+ it "parses a full year with trailing numbers" do
168
+ Date.strptime("20000", "%Y0").should == Date.civil(2000, 1, 1)
169
+ Date.strptime("200002", "%Y%m").should == Date.civil(2000, 2, 1)
157
170
  end
158
171
 
159
172
  it "parses a year in YY format" do
@@ -164,6 +177,11 @@ describe "Date#strptime" do
164
177
  Date.strptime("00 % \n \t %1", "%y %% %n %t %%1").should == Date.civil(2000, 1, 1)
165
178
  end
166
179
 
180
+ it "parse a %Y%m%d date" do
181
+ Date.strptime("20000203", "%Y%m%d").should == Date.civil(2000, 2, 3)
182
+ end
183
+
184
+
167
185
  ############################
168
186
  # Specs that combine stuff #
169
187
  ############################
@@ -173,6 +191,11 @@ describe "Date#strptime" do
173
191
  Date.strptime("Thu Apr 6 00:00:00 2000", "%a %b %e %H:%M:%S %Y").should == Date.civil(2000, 4, 6)
174
192
  end
175
193
 
194
+ it "parses a full date with trailing digits" do
195
+ Date.strptime("Thu Apr 6 00:00:00 20000", "%c0").should == Date.civil(2000, 4, 6)
196
+ Date.strptime("Thu Apr 6 00:00:00 200012", "%c%m").should == Date.civil(2000, 12, 6)
197
+ end
198
+
176
199
  it "parses a date with slashes" do
177
200
  Date.strptime("04/06/00", "%D").should == Date.civil(2000, 4, 6)
178
201
  Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
@@ -183,11 +206,16 @@ describe "Date#strptime" do
183
206
  Date.strptime("2000-04-06", "%Y-%m-%d").should == Date.civil(2000, 4, 6)
184
207
  end
185
208
 
186
- it "parses a commercial week" do
209
+ it "parses a civil format with month name" do
187
210
  Date.strptime(" 9-Apr-2000", "%v").should == Date.civil(2000, 4, 9)
188
211
  Date.strptime(" 9-Apr-2000", "%e-%b-%Y").should == Date.civil(2000, 4, 9)
189
212
  end
190
213
 
214
+ it "parses a civil format with month name with trailing digits" do
215
+ Date.strptime(" 9-Apr-20000", "%v0").should == Date.civil(2000, 4, 9)
216
+ Date.strptime(" 9-Apr-200012", "%v%m").should == Date.civil(2000, 12, 9)
217
+ end
218
+
191
219
  it "parses a date given MM/DD/YY" do
192
220
  Date.strptime("04/06/00", "%x").should == Date.civil(2000, 4, 6)
193
221
  Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
@@ -198,4 +226,8 @@ describe "Date#strptime" do
198
226
  Date.strptime("Sun Apr 9 00:00:00 +00:00 2000", "%a %b %e %H:%M:%S %Z %Y").should == Date.civil(2000, 4, 9)
199
227
  end
200
228
 
229
+ it "parses a date given in full notation with trailing digits" do
230
+ Date.strptime("Sun Apr 9 00:00:00 +00:00 20000", "%+0").should == Date.civil(2000, 4, 9)
231
+ Date.strptime("Sun Apr 9 00:00:00 +00:00 200012", "%+%m").should == Date.civil(2000, 12, 9)
232
+ end
201
233
  end
@@ -27,10 +27,10 @@ describe "DateTime#+" do
27
27
  end
28
28
 
29
29
  it "should raise an error on non numeric parameters" do
30
- lambda { DateTime.civil(2007,2,27) + :hello }.should raise_error(TypeError)
31
- lambda { DateTime.civil(2007,2,27) + "hello" }.should raise_error(TypeError)
32
- lambda { DateTime.civil(2007,2,27) + DateTime.new(2007,2,27) }.should raise_error(TypeError)
33
- lambda { DateTime.civil(2007,2,27) + Object.new }.should raise_error(TypeError)
30
+ lambda { DateTime.civil(2007,2,27) + :hello }.should raise_error
31
+ lambda { DateTime.civil(2007,2,27) + "hello" }.should raise_error
32
+ lambda { DateTime.civil(2007,2,27) + DateTime.new(2007,2,27) }.should raise_error
33
+ lambda { DateTime.civil(2007,2,27) + Object.new }.should raise_error
34
34
  end
35
35
 
36
36
  end
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Date.allocate" do
4
+ it "should not be defined" do
5
+ proc{DateTime.allocate}.should raise_error
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ ruby_version_is "1.9" do
4
+ describe "DateTime string encoding methods" do
5
+ it "should return strings in US-ASCII encoding by default" do
6
+ d = DateTime.now
7
+ d.asctime.encoding.name.should == 'US-ASCII'
8
+ d.ctime.encoding.name.should == 'US-ASCII'
9
+ d.httpdate.encoding.name.should == 'US-ASCII'
10
+ d.inspect.encoding.name.should == 'US-ASCII'
11
+ d.iso8601.encoding.name.should == 'US-ASCII'
12
+ d.jisx0301.encoding.name.should == 'US-ASCII'
13
+ d.rfc2822.encoding.name.should == 'US-ASCII'
14
+ d.rfc3339.encoding.name.should == 'US-ASCII'
15
+ d.rfc822.encoding.name.should == 'US-ASCII'
16
+ d.strftime('%S:%M:%H').encoding.name.should == 'US-ASCII'
17
+ d.to_s.encoding.name.should == 'US-ASCII'
18
+ d.xmlschema.encoding.name.should == 'US-ASCII'
19
+ end
20
+
21
+ it "should return strings in default_internal encoding if set" do
22
+ begin
23
+ Encoding.default_internal = 'UTF-8'
24
+ d = DateTime.now
25
+ d.asctime.encoding.name.should == 'UTF-8'
26
+ d.ctime.encoding.name.should == 'UTF-8'
27
+ d.httpdate.encoding.name.should == 'UTF-8'
28
+ d.inspect.encoding.name.should == 'UTF-8'
29
+ d.iso8601.encoding.name.should == 'UTF-8'
30
+ d.jisx0301.encoding.name.should == 'UTF-8'
31
+ d.rfc2822.encoding.name.should == 'UTF-8'
32
+ d.rfc3339.encoding.name.should == 'UTF-8'
33
+ d.rfc822.encoding.name.should == 'UTF-8'
34
+ d.strftime('%S:%M:%H').encoding.name.should == 'UTF-8'
35
+ d.to_s.encoding.name.should == 'UTF-8'
36
+ d.xmlschema.encoding.name.should == 'UTF-8'
37
+ ensure
38
+ Encoding.default_internal = nil
39
+ end
40
+ end
41
+ end
42
+ end