home_run 0.9.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +19 -0
- data/README.rdoc +314 -0
- data/Rakefile +136 -0
- data/bench/cpu_bench.rb +279 -0
- data/bench/dt_garbage_bench.rb +11 -0
- data/bench/dt_mem_bench.rb +14 -0
- data/bench/garbage_bench.rb +11 -0
- data/bench/mem_bench.rb +14 -0
- data/bin/home_run +91 -0
- data/default.mspec +12 -0
- data/ext/1.8/date_ext.so +0 -0
- data/ext/1.9/date_ext.so +0 -0
- data/ext/date.rb +7 -0
- data/ext/date/format.rb +842 -0
- data/ext/date_ext.c +4548 -0
- data/ext/date_parser.c +367 -0
- data/ext/date_parser.rl +134 -0
- data/ext/datetime.c +2804 -0
- data/ext/extconf.rb +6 -0
- data/spec/date/accessor_spec.rb +176 -0
- data/spec/date/add_month_spec.rb +26 -0
- data/spec/date/add_spec.rb +23 -0
- data/spec/date/boat_spec.rb +38 -0
- data/spec/date/civil_spec.rb +147 -0
- data/spec/date/commercial_spec.rb +153 -0
- data/spec/date/constants_spec.rb +44 -0
- data/spec/date/conversions_spec.rb +246 -0
- data/spec/date/day_spec.rb +73 -0
- data/spec/date/downto_spec.rb +17 -0
- data/spec/date/eql_spec.rb +16 -0
- data/spec/date/format_spec.rb +52 -0
- data/spec/date/gregorian_spec.rb +52 -0
- data/spec/date/hash_spec.rb +11 -0
- data/spec/date/julian_spec.rb +129 -0
- data/spec/date/leap_spec.rb +19 -0
- data/spec/date/minus_month_spec.rb +25 -0
- data/spec/date/minus_spec.rb +51 -0
- data/spec/date/next_prev_spec.rb +108 -0
- data/spec/date/ordinal_spec.rb +83 -0
- data/spec/date/parse_spec.rb +442 -0
- data/spec/date/parsing_spec.rb +77 -0
- data/spec/date/relationship_spec.rb +28 -0
- data/spec/date/step_spec.rb +109 -0
- data/spec/date/strftime_spec.rb +223 -0
- data/spec/date/strptime_spec.rb +201 -0
- data/spec/date/succ_spec.rb +20 -0
- data/spec/date/today_spec.rb +15 -0
- data/spec/date/upto_spec.rb +17 -0
- data/spec/datetime/accessor_spec.rb +218 -0
- data/spec/datetime/add_month_spec.rb +26 -0
- data/spec/datetime/add_spec.rb +36 -0
- data/spec/datetime/boat_spec.rb +43 -0
- data/spec/datetime/constructor_spec.rb +142 -0
- data/spec/datetime/conversions_spec.rb +54 -0
- data/spec/datetime/day_spec.rb +73 -0
- data/spec/datetime/downto_spec.rb +39 -0
- data/spec/datetime/eql_spec.rb +17 -0
- data/spec/datetime/format_spec.rb +59 -0
- data/spec/datetime/hash_spec.rb +11 -0
- data/spec/datetime/leap_spec.rb +19 -0
- data/spec/datetime/minus_month_spec.rb +25 -0
- data/spec/datetime/minus_spec.rb +77 -0
- data/spec/datetime/next_prev_spec.rb +138 -0
- data/spec/datetime/now_spec.rb +18 -0
- data/spec/datetime/parse_spec.rb +390 -0
- data/spec/datetime/parsing_spec.rb +77 -0
- data/spec/datetime/relationship_spec.rb +28 -0
- data/spec/datetime/step_spec.rb +155 -0
- data/spec/datetime/strftime_spec.rb +118 -0
- data/spec/datetime/strptime_spec.rb +117 -0
- data/spec/datetime/succ_spec.rb +24 -0
- data/spec/datetime/upto_spec.rb +39 -0
- data/spec/spec_helper.rb +59 -0
- metadata +154 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#===" do
|
4
|
+
|
5
|
+
it "should be true for the two same dates" do
|
6
|
+
(Date.civil(2000, 04, 06) === Date.civil(2000, 04, 06)).should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be true if comparison is a DateTime on the same date" do
|
10
|
+
(Date.civil(2000, 04, 06) === DateTime.civil(2000, 04, 06, 10)).should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be true if comparison is a Numeric with the same integer value as JD" do
|
14
|
+
(Date.civil(2000, 04, 06) === Date.civil(2000, 04, 06).jd).should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be false for different dates" do
|
18
|
+
(Date.civil(2000, 04, 05) === Date.civil(2000, 04, 06)).should == false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be false if comparison is a DateTime with a different date" do
|
22
|
+
(Date.civil(2000, 04, 06) === DateTime.civil(2000, 04, 07, 10)).should == false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be false if comparison is a Numeric with the different integer value as JD" do
|
26
|
+
(Date.civil(2000, 04, 06) === Date.civil(2000, 04, 07).jd).should == false
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#step" do
|
4
|
+
|
5
|
+
it "should be able to step forward in time" do
|
6
|
+
ds = Date.civil(2008, 10, 11)
|
7
|
+
de = Date.civil(2008, 9, 29)
|
8
|
+
count = 0
|
9
|
+
de.step(ds) do |d|
|
10
|
+
d.should <= ds
|
11
|
+
d.should >= de
|
12
|
+
count += 1
|
13
|
+
end.should == de
|
14
|
+
count.should == 13
|
15
|
+
|
16
|
+
count = 0
|
17
|
+
de.step(ds, 5) do |d|
|
18
|
+
d.should <= ds
|
19
|
+
d.should >= de
|
20
|
+
count += 1
|
21
|
+
end.should == de
|
22
|
+
count.should == 3
|
23
|
+
|
24
|
+
count = 0
|
25
|
+
ds.step(de) do |d|; count += 1; end.should == ds
|
26
|
+
count.should == 0
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to step backward in time" do
|
31
|
+
ds = Date.civil(2000, 4, 14)
|
32
|
+
de = Date.civil(2000, 3, 29)
|
33
|
+
count = 0
|
34
|
+
ds.step(de, -1) do |d|
|
35
|
+
d.should <= ds
|
36
|
+
d.should >= de
|
37
|
+
count += 1
|
38
|
+
end.should == ds
|
39
|
+
count.should == 17
|
40
|
+
|
41
|
+
count = 0
|
42
|
+
ds.step(de, -5) do |d|
|
43
|
+
d.should <= ds
|
44
|
+
d.should >= de
|
45
|
+
count += 1
|
46
|
+
end.should == ds
|
47
|
+
count.should == 4
|
48
|
+
|
49
|
+
count = 0
|
50
|
+
de.step(ds, -1) do |d|; count += 1; end.should == de
|
51
|
+
count.should == 0
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should yield once if the dates are the same, regardless of step" do
|
56
|
+
ds = Date.civil(2008, 10, 11)
|
57
|
+
count = 0
|
58
|
+
ds.step(ds, 1) do |d|
|
59
|
+
d.should == ds
|
60
|
+
count += 1
|
61
|
+
end.should == ds
|
62
|
+
count.should == 1
|
63
|
+
|
64
|
+
count = 0
|
65
|
+
ds.step(ds, 0) do |d|
|
66
|
+
d.should == ds
|
67
|
+
count += 1
|
68
|
+
end.should == ds
|
69
|
+
count.should == 1
|
70
|
+
|
71
|
+
count = 0
|
72
|
+
ds.step(ds, -1) do |d|
|
73
|
+
d.should == ds
|
74
|
+
count += 1
|
75
|
+
end.should == ds
|
76
|
+
count.should == 1
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should not yield if the target date is greater than the receiver, and step is not positive" do
|
80
|
+
ds = Date.civil(2008, 10, 11)
|
81
|
+
count = 0
|
82
|
+
ds.step(ds.next, 0) do |d|
|
83
|
+
count += 1
|
84
|
+
end.should == ds
|
85
|
+
count.should == 0
|
86
|
+
|
87
|
+
count = 0
|
88
|
+
ds.step(ds.next, -1) do |d|
|
89
|
+
count += 1
|
90
|
+
end.should == ds
|
91
|
+
count.should == 0
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not yield if the target date is less than the receiver, and step is not negative" do
|
95
|
+
ds = Date.civil(2008, 10, 11)
|
96
|
+
count = 0
|
97
|
+
ds.next.step(ds, 0) do |d|
|
98
|
+
count += 1
|
99
|
+
end.should == ds.next
|
100
|
+
count.should == 0
|
101
|
+
|
102
|
+
count = 0
|
103
|
+
ds.next.step(ds, 1) do |d|
|
104
|
+
count += 1
|
105
|
+
end.should == ds.next
|
106
|
+
count.should == 0
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#strftime" do
|
4
|
+
|
5
|
+
it "should be able to print the date" do
|
6
|
+
Date.civil(2000, 4, 6).strftime.should == "2000-04-06"
|
7
|
+
Date.civil(2000, 4, 6).strftime.should == Date.civil(2000, 4, 6).to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to print the full day name" do
|
11
|
+
Date.civil(2000, 4, 6).strftime("%A").should == "Thursday"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to print the short day name" do
|
15
|
+
Date.civil(2000, 4, 6).strftime("%a").should == "Thu"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to print the full month name" do
|
19
|
+
Date.civil(2000, 4, 6).strftime("%B").should == "April"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be able to print the short month name" do
|
23
|
+
Date.civil(2000, 4, 6).strftime("%b").should == "Apr"
|
24
|
+
Date.civil(2000, 4, 6).strftime("%h").should == "Apr"
|
25
|
+
Date.civil(2000, 4, 6).strftime("%b").should == Date.civil(2000, 4, 6).strftime("%h")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to print the century" do
|
29
|
+
Date.civil(2000, 4, 6).strftime("%C").should == "20"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be able to print the month day with leading zeroes" do
|
33
|
+
Date.civil(2000, 4, 6).strftime("%d").should == "06"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to print the month day with leading spaces" do
|
37
|
+
Date.civil(2000, 4, 6).strftime("%e").should == " 6"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to print the commercial year with leading zeroes" do
|
41
|
+
Date.civil(2000, 4, 6).strftime("%G").should == "2000"
|
42
|
+
Date.civil( 200, 4, 6).strftime("%G").should == "0200"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be able to print the commercial year with only two digits" do
|
46
|
+
Date.civil(2000, 4, 6).strftime("%g").should == "00"
|
47
|
+
Date.civil( 200, 4, 6).strftime("%g").should == "00"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to print the hour with leading zeroes (hour is always 00)" do
|
51
|
+
Date.civil(2000, 4, 6).strftime("%H").should == "00"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be able to print the hour in 12 hour notation with leading zeroes" do
|
55
|
+
Date.civil(2000, 4, 6).strftime("%I").should == "12"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be able to print the year day with leading zeroes" do
|
59
|
+
Date.civil(2000, 4, 6).strftime("%j").should == "097"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be able to print the hour in 24 hour notation with leading spaces" do
|
63
|
+
Date.civil(2000, 4, 6).strftime("%k").should == " 0"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be able to print the hour in 12 hour notation with leading spaces" do
|
67
|
+
Date.civil(2000, 4, 6).strftime("%l").should == "12"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should be able to print the milliseconds of the second with leading zeroes" do
|
71
|
+
Date.civil(2000, 4, 6).strftime("%L").should == "000"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should be able to print the minutes with leading zeroes" do
|
75
|
+
Date.civil(2000, 4, 6).strftime("%M").should == "00"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be able to print the month with leading zeroes" do
|
79
|
+
Date.civil(2000, 4, 6).strftime("%m").should == "04"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should be able to print the nanoseconds of the second with leading zeroes" do
|
83
|
+
Date.civil(2000, 4, 6).strftime("%N").should == "000000000"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be able to add a newline" do
|
87
|
+
Date.civil(2000, 4, 6).strftime("%n").should == "\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should be able to show AM/PM" do
|
91
|
+
Date.civil(2000, 4, 6).strftime("%P").should == "am"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be able to show am/pm" do
|
95
|
+
Date.civil(2000, 4, 6).strftime("%p").should == "AM"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be able to show the number of milliseconds since the unix epoch" do
|
99
|
+
Date.civil(2000, 4, 6).strftime("%Q").should == "954979200000"
|
100
|
+
Date.civil(3000, 4, 6).strftime("%Q").should == "32511888000000"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be able to show the number of seconds with leading zeroes" do
|
104
|
+
Date.civil(2000, 4, 6).strftime("%S").should == "00"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be able to show the number of seconds since the unix epoch" do
|
108
|
+
Date.civil(2000, 4, 6).strftime("%s").should == "954979200"
|
109
|
+
Date.civil(3000, 4, 6).strftime("%s").should == "32511888000"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should be able to add a tab" do
|
113
|
+
Date.civil(2000, 4, 6).strftime("%t").should == "\t"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be able to show the week number with the week starting on sunday and monday" do
|
117
|
+
Date.civil(2000, 4, 6).strftime("%U").should == "14"
|
118
|
+
Date.civil(2000, 4, 6).strftime("%W").should == "14"
|
119
|
+
Date.civil(2000, 4, 6).strftime("%U").should == Date.civil(2000, 4, 6).strftime("%W")
|
120
|
+
Date.civil(2000, 4, 9).strftime("%U").should == "15"
|
121
|
+
Date.civil(2000, 4, 9).strftime("%W").should == "14"
|
122
|
+
Date.civil(2000, 4, 9).strftime("%U").should_not == Date.civil(2000, 4, 9).strftime("%W")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should be able to show the commercial week day" do
|
126
|
+
Date.civil(2000, 4, 9).strftime("%u").should == "7"
|
127
|
+
Date.civil(2000, 4, 10).strftime("%u").should == "1"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be able to show the commercial week" do
|
131
|
+
Date.civil(2000, 4, 9).strftime("%V").should == "14"
|
132
|
+
Date.civil(2000, 4, 10).strftime("%V").should == "15"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be able to show the week day" do
|
136
|
+
Date.civil(2000, 4, 9).strftime("%w").should == "0"
|
137
|
+
Date.civil(2000, 4, 10).strftime("%w").should == "1"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should be able to show the year in YYYY format" do
|
141
|
+
Date.civil(2000, 4, 9).strftime("%Y").should == "2000"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should be able to show the year in YY format" do
|
145
|
+
Date.civil(2000, 4, 9).strftime("%y").should == "00"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should be able to show the timezone of the date with a : separator" do
|
149
|
+
Date.civil(2000, 4, 9).strftime("%Z").should == "+00:00"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should be able to show the timezone of the date with a : separator" do
|
153
|
+
Date.civil(2000, 4, 9).strftime("%z").should == "+0000"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should be able to escape the % character" do
|
157
|
+
Date.civil(2000, 4, 9).strftime("%%").should == "%"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should remove % from other %X sequences if it doesn't have a conversion" do
|
161
|
+
Date.civil(2000, 4, 9).strftime("%5").should == "5"
|
162
|
+
Date.civil(2000, 4, 9).strftime("%f").should == "f"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should leave other text alone if it doesn't have a conversion" do
|
166
|
+
Date.civil(2000, 4, 9).strftime("15").should == "15"
|
167
|
+
end
|
168
|
+
|
169
|
+
############################
|
170
|
+
# Specs that combine stuff #
|
171
|
+
############################
|
172
|
+
|
173
|
+
it "should be able to print the date in full" do
|
174
|
+
Date.civil(2000, 4, 6).strftime("%c").should == "Thu Apr 6 00:00:00 2000"
|
175
|
+
Date.civil(2000, 4, 6).strftime("%c").should == Date.civil(2000, 4, 6).strftime('%a %b %e %H:%M:%S %Y')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should be able to print the date with slashes" do
|
179
|
+
Date.civil(2000, 4, 6).strftime("%D").should == "04/06/00"
|
180
|
+
Date.civil(2000, 4, 6).strftime("%D").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should be able to print the date as YYYY-MM-DD" do
|
184
|
+
Date.civil(2000, 4, 6).strftime("%F").should == "2000-04-06"
|
185
|
+
Date.civil(2000, 4, 6).strftime("%F").should == Date.civil(2000, 4, 6).strftime('%Y-%m-%d')
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should be able to show HH:MM" do
|
189
|
+
Date.civil(2000, 4, 6).strftime("%R").should == "00:00"
|
190
|
+
Date.civil(2000, 4, 6).strftime("%R").should == Date.civil(2000, 4, 6).strftime('%H:%M')
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should be able to show HH:MM:SS AM/PM" do
|
194
|
+
Date.civil(2000, 4, 6).strftime("%r").should == "12:00:00 AM"
|
195
|
+
Date.civil(2000, 4, 6).strftime("%r").should == Date.civil(2000, 4, 6).strftime('%I:%M:%S %p')
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should be able to show HH:MM:SS" do
|
199
|
+
Date.civil(2000, 4, 6).strftime("%T").should == "00:00:00"
|
200
|
+
Date.civil(2000, 4, 6).strftime("%T").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should be able to show the commercial week" do
|
204
|
+
Date.civil(2000, 4, 9).strftime("%v").should == " 9-Apr-2000"
|
205
|
+
Date.civil(2000, 4, 9).strftime("%v").should == Date.civil(2000, 4, 9).strftime('%e-%b-%Y')
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should be able to show HH:MM:SS" do
|
209
|
+
Date.civil(2000, 4, 6).strftime("%X").should == "00:00:00"
|
210
|
+
Date.civil(2000, 4, 6).strftime("%X").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should be able to show MM/DD/YY" do
|
214
|
+
Date.civil(2000, 4, 6).strftime("%x").should == "04/06/00"
|
215
|
+
Date.civil(2000, 4, 6).strftime("%x").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should be able to show a full notation" do
|
219
|
+
Date.civil(2000, 4, 9).strftime("%+").should == "Sun Apr 9 00:00:00 +00:00 2000"
|
220
|
+
Date.civil(2000, 4, 9).strftime("%+").should == Date.civil(2000, 4, 9).strftime('%a %b %e %H:%M:%S %Z %Y')
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#strptime" do
|
4
|
+
|
5
|
+
it "._strptime should not accept less than 1 arguments" do
|
6
|
+
proc{Date._strptime}.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "._strptime should not accept more than 2 arguments" do
|
10
|
+
proc{Date._strptime('2008-10-11', '%Y-%m-%d', '1')}.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "._strptime should be a hash of values" do
|
14
|
+
Date._strptime('2008-10-11').should == {:year=>2008, :mon=>10, :mday=>11}
|
15
|
+
Date._strptime('2008-10-11', '%Y-%m-%d').should == {:year=>2008, :mon=>10, :mday=>11}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have defaults and an optional sg value" do
|
19
|
+
Date.strptime.should == Date.jd
|
20
|
+
Date.strptime('2008-10-11').should == Date.civil(2008, 10, 11)
|
21
|
+
Date.strptime('2008-10-11', '%Y-%m-%d').should == Date.civil(2008, 10, 11)
|
22
|
+
Date.strptime('2008-10-11', '%Y-%m-%d', 1).should == Date.civil(2008, 10, 11)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises errors for invalid dates" do
|
26
|
+
lambda { Date.strptime("") }.should raise_error(ArgumentError)
|
27
|
+
lambda { Date.strptime("", "") }.should raise_error(ArgumentError)
|
28
|
+
lambda { Date.strptime("2009-02-29") }.should raise_error(ArgumentError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "uses the default format when not given a date format" do
|
32
|
+
Date.strptime("2000-04-06").should == Date.civil(2000, 4, 6)
|
33
|
+
Date.civil(2000, 4, 6).strftime.should == Date.civil(2000, 4, 6).to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses a full day name" do
|
37
|
+
d = Date.today
|
38
|
+
expected_date = Date.commercial(d.cwyear, d.cweek, 4)
|
39
|
+
# strptime assumed week that start on sunday, not monday
|
40
|
+
expected_date += 7 if d.cwday == 7
|
41
|
+
Date.strptime("Thursday", "%A").should == expected_date
|
42
|
+
end
|
43
|
+
|
44
|
+
it "parses a short day name" do
|
45
|
+
d = Date.today
|
46
|
+
expected_date = Date.commercial(d.cwyear, d.cweek, 4)
|
47
|
+
# strptime assumed week that start on sunday, not monday
|
48
|
+
expected_date += 7 if d.cwday == 7
|
49
|
+
Date.strptime("Thu", "%a").should == expected_date
|
50
|
+
end
|
51
|
+
|
52
|
+
it "parses only the short part of the day name" do
|
53
|
+
Date._strptime("Friday", "%aday").should == {:wday=>5}
|
54
|
+
end
|
55
|
+
|
56
|
+
it "parses a full month name" do
|
57
|
+
d = Date.today
|
58
|
+
Date.strptime("April", "%B").should == Date.civil(d.year, 4, 1)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "parses a short month name" do
|
62
|
+
d = Date.today
|
63
|
+
Date.strptime("Apr", "%b").should == Date.civil(d.year, 4, 1)
|
64
|
+
Date.strptime("Apr", "%h").should == Date.civil(d.year, 4, 1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "parses only the short part of the month name" do
|
68
|
+
d = Date.today
|
69
|
+
Date.strptime("April", "%bil").should == Date.civil(d.year, 4, 1)
|
70
|
+
Date.strptime("April", "%hil").should == Date.civil(d.year, 4, 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "parses a century" do
|
74
|
+
Date.strptime("06 20", "%y %C").should == Date.civil(2006, 1, 1)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "parses a month day with leading zeroes" do
|
78
|
+
d = Date.today
|
79
|
+
Date.strptime("06", "%d").should == Date.civil(d.year, d.month, 6)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "parses a month day with leading spaces" do
|
83
|
+
d = Date.today
|
84
|
+
Date.strptime(" 6", "%e").should == Date.civil(d.year, d.month, 6)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "parses a commercial year with leading zeroes" do
|
88
|
+
Date.strptime("2000", "%G").should == Date.civil(2000, 1, 3)
|
89
|
+
Date.strptime("2002", "%G").should == Date.civil(2001, 12, 31)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "parses a commercial year with only two digits" do
|
93
|
+
Date.strptime("68", "%g").should == Date.civil(2068, 1, 2)
|
94
|
+
Date.strptime("69", "%g").should == Date.civil(1968, 12, 30)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "parses a year day with leading zeroes" do
|
98
|
+
d = Date.today
|
99
|
+
if Date.gregorian_leap?(Date.today.year)
|
100
|
+
Date.strptime("097", "%j").should == Date.civil(d.year, 4, 6)
|
101
|
+
else
|
102
|
+
Date.strptime("097", "%j").should == Date.civil(d.year, 4, 7)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "parses a month with leading zeroes" do
|
107
|
+
d = Date.today
|
108
|
+
Date.strptime("04", "%m").should == Date.civil(d.year, 4, 1)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be able to parse the number of seconds since the unix epoch" do
|
112
|
+
Date.strptime("954979200000", "%Q").should == Date.civil(2000, 4, 6)
|
113
|
+
Date.strptime("32511888000000", "%Q").should == Date.civil(3000, 4, 6)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be able to parse the number of seconds since the unix epoch" do
|
117
|
+
Date.strptime("954979200", "%s").should == Date.civil(2000, 4, 6)
|
118
|
+
Date.strptime("32511888000", "%s").should == Date.civil(3000, 4, 6)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be able to pase the commercial day" do
|
122
|
+
Date.strptime("1", "%u").should == Date.commercial(Date.today.year, 1, 1)
|
123
|
+
Date.strptime("15 3", "%V %u").should == Date.commercial(Date.today.year, 15, 3)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should be able to show the commercial week" do
|
127
|
+
d = Date.commercial(Date.today.year,1,1)
|
128
|
+
Date.strptime("1", "%V").should == d
|
129
|
+
Date.strptime("15", "%V").should == Date.commercial(d.cwyear, 15, 1)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "parses a week number for a week starting on Sunday" do
|
133
|
+
Date.strptime("2010/1", "%Y/%U").should == Date.civil(2010, 1, 3)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "parses a week number for a week starting on Monday" do
|
137
|
+
Date.strptime("2010/1", "%Y/%W").should == Date.civil(2010, 1, 4)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "parses a commercial week day" do
|
141
|
+
Date.strptime("2008 1", "%G %u").should == Date.civil(2007, 12, 31)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "parses a commercial week" do
|
145
|
+
d = Date.commercial(Date.today.cwyear,1,1)
|
146
|
+
Date.strptime("1", "%V").should == d
|
147
|
+
Date.strptime("15", "%V").should == Date.commercial(d.cwyear, 15, 1)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "parses a week day" do
|
151
|
+
d = Date.today
|
152
|
+
Date.strptime("2007 4", "%Y %w").should == Date.civil(2007, 1, 4)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "parses a year in YYYY format" do
|
156
|
+
Date.strptime("2007", "%Y").should == Date.civil(2007, 1, 1)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "parses a year in YY format" do
|
160
|
+
Date.strptime("00", "%y").should == Date.civil(2000, 1, 1)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should be able to parse escapes" do
|
164
|
+
Date.strptime("00 % \n \t %1", "%y %% %n %t %%1").should == Date.civil(2000, 1, 1)
|
165
|
+
end
|
166
|
+
|
167
|
+
############################
|
168
|
+
# Specs that combine stuff #
|
169
|
+
############################
|
170
|
+
|
171
|
+
it "parses a full date" do
|
172
|
+
Date.strptime("Thu Apr 6 00:00:00 2000", "%c").should == Date.civil(2000, 4, 6)
|
173
|
+
Date.strptime("Thu Apr 6 00:00:00 2000", "%a %b %e %H:%M:%S %Y").should == Date.civil(2000, 4, 6)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "parses a date with slashes" do
|
177
|
+
Date.strptime("04/06/00", "%D").should == Date.civil(2000, 4, 6)
|
178
|
+
Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "parses a date given as YYYY-MM-DD" do
|
182
|
+
Date.strptime("2000-04-06", "%F").should == Date.civil(2000, 4, 6)
|
183
|
+
Date.strptime("2000-04-06", "%Y-%m-%d").should == Date.civil(2000, 4, 6)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "parses a commercial week" do
|
187
|
+
Date.strptime(" 9-Apr-2000", "%v").should == Date.civil(2000, 4, 9)
|
188
|
+
Date.strptime(" 9-Apr-2000", "%e-%b-%Y").should == Date.civil(2000, 4, 9)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "parses a date given MM/DD/YY" do
|
192
|
+
Date.strptime("04/06/00", "%x").should == Date.civil(2000, 4, 6)
|
193
|
+
Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "parses a date given in full notation" do
|
197
|
+
Date.strptime("Sun Apr 9 00:00:00 +00:00 2000", "%+").should == Date.civil(2000, 4, 9)
|
198
|
+
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
|
+
end
|
200
|
+
|
201
|
+
end
|