home_run 0.9.0-x86-mswin32
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 +135 -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,18 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime.now" do
|
4
|
+
it "should be right now as a DateTime" do
|
5
|
+
t = Time.now
|
6
|
+
d = DateTime.now
|
7
|
+
d.year.should == t.year
|
8
|
+
d.mon.should == t.mon
|
9
|
+
d.day.should == t.day
|
10
|
+
d.hour.should == t.hour
|
11
|
+
d.min.should == t.min
|
12
|
+
d.sec.should == t.sec
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accept an optional sg value" do
|
16
|
+
DateTime.now(1).to_s.should == DateTime.now.to_s
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,390 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#parse" do
|
4
|
+
|
5
|
+
it "should have defaults and an optional sg value" do
|
6
|
+
DateTime.parse('2008-10-11').should == DateTime.civil(2008, 10, 11)
|
7
|
+
DateTime.parse('2008-10-11', true).should == DateTime.civil(2008, 10, 11)
|
8
|
+
DateTime.parse('2008-10-11', true, 1).should == DateTime.civil(2008, 10, 11)
|
9
|
+
DateTime.parse.should == DateTime.jd
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can't handle a empty string" do
|
13
|
+
lambda{ DateTime.parse("") }.should raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Specs using numbers
|
17
|
+
it "can't handle a single digit" do
|
18
|
+
lambda{ DateTime.parse("1") }.should raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can handle many different types of time values" do
|
22
|
+
DateTime.parse("01:02:03").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3)
|
23
|
+
DateTime.parse("01:02:03am").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3)
|
24
|
+
DateTime.parse(" 1:02:03am").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3)
|
25
|
+
DateTime.parse("1:02:03am").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3)
|
26
|
+
DateTime.parse("01:02:03am").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3)
|
27
|
+
DateTime.parse("01:02:03pm").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 13, 2, 3)
|
28
|
+
DateTime.parse("01:02:03pm").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 13, 2, 3)
|
29
|
+
DateTime.parse("12:02:03am").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 0, 2, 3)
|
30
|
+
DateTime.parse("12:02:03pm").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 12, 2, 3)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should assume no time offset if no time offset is specified" do
|
34
|
+
DateTime.parse("01:02:03").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, 0)
|
35
|
+
DateTime.parse("01:02:03Z").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, 0)
|
36
|
+
DateTime.parse("01:02:03+0100").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, 1/24.0)
|
37
|
+
DateTime.parse("01:02:03-01:00").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, -1/24.0)
|
38
|
+
DateTime.parse("01:02:03+01").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, 1/24.0)
|
39
|
+
DateTime.parse("01:02:03-01").should == DateTime.civil(Date.today.year, Date.today.month, Date.today.day, 1, 2, 3, -1/24.0)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should parse the time zone abbreviations supported by ruby's Time class" do
|
43
|
+
DateTime.parse("01:02:03 UTC").offset.should == 0
|
44
|
+
DateTime.parse("01:02:03 UT").offset.should == 0
|
45
|
+
DateTime.parse("01:02:03 GMT").offset.should == 0
|
46
|
+
DateTime.parse("01:02:03 EST").offset.should == -5/24.0
|
47
|
+
DateTime.parse("01:02:03 EDT").offset.should == -4/24.0
|
48
|
+
DateTime.parse("01:02:03 CST").offset.should == -6/24.0
|
49
|
+
DateTime.parse("01:02:03 CDT").offset.should == -5/24.0
|
50
|
+
DateTime.parse("01:02:03 MST").offset.should == -7/24.0
|
51
|
+
DateTime.parse("01:02:03 MDT").offset.should == -6/24.0
|
52
|
+
DateTime.parse("01:02:03 PST").offset.should == -8/24.0
|
53
|
+
DateTime.parse("01:02:03 PDT").offset.should == -7/24.0
|
54
|
+
DateTime.parse("01:02:03 A").offset.should == 1/24.0
|
55
|
+
DateTime.parse("01:02:03 B").offset.should == 2/24.0
|
56
|
+
DateTime.parse("01:02:03 C").offset.should == 3/24.0
|
57
|
+
DateTime.parse("01:02:03 D").offset.should == 4/24.0
|
58
|
+
DateTime.parse("01:02:03 E").offset.should == 5/24.0
|
59
|
+
DateTime.parse("01:02:03 F").offset.should == 6/24.0
|
60
|
+
DateTime.parse("01:02:03 G").offset.should == 7/24.0
|
61
|
+
DateTime.parse("01:02:03 H").offset.should == 8/24.0
|
62
|
+
DateTime.parse("01:02:03 I").offset.should == 9/24.0
|
63
|
+
DateTime.parse("01:02:03 K").offset.should == 10/24.0
|
64
|
+
DateTime.parse("01:02:03 L").offset.should == 11/24.0
|
65
|
+
DateTime.parse("01:02:03 M").offset.should == 12/24.0
|
66
|
+
DateTime.parse("01:02:03 N").offset.should == -1/24.0
|
67
|
+
DateTime.parse("01:02:03 O").offset.should == -2/24.0
|
68
|
+
DateTime.parse("01:02:03 P").offset.should == -3/24.0
|
69
|
+
DateTime.parse("01:02:03 Q").offset.should == -4/24.0
|
70
|
+
DateTime.parse("01:02:03 R").offset.should == -5/24.0
|
71
|
+
DateTime.parse("01:02:03 S").offset.should == -6/24.0
|
72
|
+
DateTime.parse("01:02:03 T").offset.should == -7/24.0
|
73
|
+
DateTime.parse("01:02:03 U").offset.should == -8/24.0
|
74
|
+
DateTime.parse("01:02:03 V").offset.should == -9/24.0
|
75
|
+
DateTime.parse("01:02:03 W").offset.should == -10/24.0
|
76
|
+
DateTime.parse("01:02:03 X").offset.should == -11/24.0
|
77
|
+
DateTime.parse("01:02:03 Y").offset.should == -12/24.0
|
78
|
+
DateTime.parse("01:02:03 Z").offset.should == 0
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should parse the time strings output by ruby's Time class" do
|
82
|
+
proc{DateTime.parse(Time.now.to_s)}.should_not raise_error
|
83
|
+
end
|
84
|
+
|
85
|
+
it "can handle DD as month day number" do
|
86
|
+
DateTime.parse("10").should == DateTime.civil(Date.today.year, Date.today.month, 10)
|
87
|
+
DateTime.parse("10 01:02:03").should == DateTime.civil(Date.today.year, Date.today.month, 10, 1, 2, 3)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can handle DDD as year day number" do
|
91
|
+
DateTime.parse("050").should == DateTime.civil(Date.today.year, 2, 19)
|
92
|
+
DateTime.parse("050 1:02:03").should == DateTime.civil(Date.today.year, 2, 19, 1, 2, 3)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "can handle MMDD as month and day" do
|
96
|
+
DateTime.parse("1108").should == DateTime.civil(Date.today.year, 11, 8)
|
97
|
+
DateTime.parse("1108 10:02:03").should == DateTime.civil(Date.today.year, 11, 8, 10, 2, 3)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "can handle YYDDD as year and day number" do
|
101
|
+
DateTime.parse("10100").should == DateTime.civil(2010, 4, 10)
|
102
|
+
DateTime.parse("10100 23:02:03").should == DateTime.civil(2010, 4, 10, 23, 2, 3)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "can handle YYMMDD as year month and day" do
|
106
|
+
DateTime.parse("201023").should == DateTime.civil(2020, 10, 23)
|
107
|
+
DateTime.parse("201023 23:02:03 +0800").should == DateTime.civil(2020, 10, 23, 23, 2, 3, 8/24.0)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can handle YYYYDDD as year and day number" do
|
111
|
+
DateTime.parse("1910100").should == DateTime.civil(1910, 4, 10)
|
112
|
+
DateTime.parse("1910100 23:02:03 -0101").should == DateTime.civil(1910, 4, 10, 23, 2, 3, -61/1440.0)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "can handle YYYYMMDD as year and day number" do
|
116
|
+
DateTime.parse("19101101").should == DateTime.civil(1910, 11, 1)
|
117
|
+
DateTime.parse("19101101T23:02:03 +0000").should == DateTime.civil(1910, 11, 1, 23, 2, 3)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe :date_parse, :shared => true do
|
122
|
+
it "can parse a mmm-YYYY string into a DateTime object" do
|
123
|
+
d = DateTime.parse("feb#{@sep}2008")
|
124
|
+
d.year.should == 2008
|
125
|
+
d.month.should == 2
|
126
|
+
d.day.should == 1
|
127
|
+
|
128
|
+
d = DateTime.parse("feb#{@sep}2008 1:02:03")
|
129
|
+
d.year.should == 2008
|
130
|
+
d.month.should == 2
|
131
|
+
d.day.should == 1
|
132
|
+
d.hour.should == 1
|
133
|
+
d.min.should == 2
|
134
|
+
d.sec.should == 3
|
135
|
+
end
|
136
|
+
|
137
|
+
it "can parse a 'DD mmm YYYY' string into a DateTime object" do
|
138
|
+
d = DateTime.parse("23#{@sep}feb#{@sep}2008")
|
139
|
+
d.year.should == 2008
|
140
|
+
d.month.should == 2
|
141
|
+
d.day.should == 23
|
142
|
+
|
143
|
+
d = DateTime.parse("23#{@sep}feb#{@sep}2008 11:02:03")
|
144
|
+
d.year.should == 2008
|
145
|
+
d.month.should == 2
|
146
|
+
d.day.should == 23
|
147
|
+
d.hour.should == 11
|
148
|
+
d.min.should == 2
|
149
|
+
d.sec.should == 3
|
150
|
+
end
|
151
|
+
|
152
|
+
it "can parse a 'mmm DD YYYY' string into a DateTime object" do
|
153
|
+
d = DateTime.parse("feb#{@sep}23#{@sep}2008")
|
154
|
+
d.year.should == 2008
|
155
|
+
d.month.should == 2
|
156
|
+
d.day.should == 23
|
157
|
+
|
158
|
+
d = DateTime.parse("feb#{@sep}23#{@sep}2008 01:02:03")
|
159
|
+
d.year.should == 2008
|
160
|
+
d.month.should == 2
|
161
|
+
d.day.should == 23
|
162
|
+
d.hour.should == 1
|
163
|
+
d.min.should == 2
|
164
|
+
d.sec.should == 3
|
165
|
+
end
|
166
|
+
|
167
|
+
it "can parse a 'YYYY mmm DD' string into a DateTime object" do
|
168
|
+
d = DateTime.parse("2008#{@sep}feb#{@sep}23")
|
169
|
+
d.year.should == 2008
|
170
|
+
d.month.should == 2
|
171
|
+
d.day.should == 23
|
172
|
+
|
173
|
+
d = DateTime.parse("2008#{@sep}feb#{@sep}23 01:02")
|
174
|
+
d.year.should == 2008
|
175
|
+
d.month.should == 2
|
176
|
+
d.day.should == 23
|
177
|
+
d.hour.should == 1
|
178
|
+
d.min.should == 2
|
179
|
+
d.sec.should == 0
|
180
|
+
end
|
181
|
+
|
182
|
+
it "can parse a month name and day into a Date object" do
|
183
|
+
DateTime.parse("november#{@sep}5th").should == DateTime.civil(Date.today.year, 11, 5)
|
184
|
+
DateTime.parse("november#{@sep}5th 1:02").should == DateTime.civil(Date.today.year, 11, 5, 1, 2)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "can parse a month name, day and year into a Date object" do
|
188
|
+
DateTime.parse("november#{@sep}5th#{@sep}2005").should == DateTime.civil(2005, 11, 5)
|
189
|
+
DateTime.parse("november#{@sep}5th#{@sep}2005 1:02").should == DateTime.civil(2005, 11, 5, 1, 2)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "can parse a year, month name and day into a Date object" do
|
193
|
+
DateTime.parse("2005#{@sep}november#{@sep}5th").should == DateTime.civil(2005, 11, 5)
|
194
|
+
DateTime.parse("2005#{@sep}november#{@sep}5th 01:02 +0100").should == DateTime.civil(2005, 11, 5, 1, 2, 0, 1/24.0)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "can parse a year, day and month name into a Date object" do
|
198
|
+
DateTime.parse("5th#{@sep}november#{@sep}2005").should == DateTime.civil(2005, 11, 5)
|
199
|
+
DateTime.parse("5th#{@sep}november#{@sep}2005 1:02 -0100").should == DateTime.civil(2005, 11, 5, 1, 2, 0, -1/24.0)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "can handle negative year numbers" do
|
203
|
+
DateTime.parse("5th#{@sep}november#{@sep}-2005").should == DateTime.civil(-2005, 11, 5)
|
204
|
+
DateTime.parse("5th#{@sep}november#{@sep}-2005 1:02 -0100").should == DateTime.civil(-2005, 11, 5, 1, 2, 0, -1/24.0)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe :date_parse_us, :shared => true do
|
209
|
+
it "parses a YYYY#{@sep}MM#{@sep}DD string into a DateTime object" do
|
210
|
+
d = DateTime.parse("2007#{@sep}10#{@sep}01")
|
211
|
+
d.year.should == 2007
|
212
|
+
d.month.should == 10
|
213
|
+
d.day.should == 1
|
214
|
+
|
215
|
+
d = DateTime.parse("2007#{@sep}10#{@sep}01 01:02:03")
|
216
|
+
d.year.should == 2007
|
217
|
+
d.month.should == 10
|
218
|
+
d.day.should == 1
|
219
|
+
d.hour.should == 1
|
220
|
+
d.min.should == 2
|
221
|
+
d.sec.should == 3
|
222
|
+
end
|
223
|
+
|
224
|
+
ruby_version_is "" ... "1.9" do
|
225
|
+
it "parses a MM#{@sep}DD#{@sep}YYYY string into a DateTime object" do
|
226
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007")
|
227
|
+
d.year.should == 2007
|
228
|
+
d.month.should == 10
|
229
|
+
d.day.should == 1
|
230
|
+
|
231
|
+
|
232
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007 01:02:03")
|
233
|
+
d.year.should == 2007
|
234
|
+
d.month.should == 10
|
235
|
+
d.day.should == 1
|
236
|
+
d.hour.should == 1
|
237
|
+
d.min.should == 2
|
238
|
+
d.sec.should == 3
|
239
|
+
end
|
240
|
+
|
241
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a DateTime object using the year digits as 20XX" do
|
242
|
+
d = DateTime.parse("10#{@sep}01#{@sep}07")
|
243
|
+
d.year.should == 2007
|
244
|
+
d.month.should == 10
|
245
|
+
d.day.should == 1
|
246
|
+
|
247
|
+
d = DateTime.parse("10#{@sep}01#{@sep}97 01:02:03 Z")
|
248
|
+
d.year.should == 1997
|
249
|
+
d.month.should == 10
|
250
|
+
d.day.should == 1
|
251
|
+
d.hour.should == 1
|
252
|
+
d.min.should == 2
|
253
|
+
d.sec.should == 3
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
ruby_version_is "1.9" do
|
258
|
+
it "parses a DD#{@sep}MM#{@sep}YYYY string into a DateTime object" do
|
259
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007")
|
260
|
+
d.year.should == 2007
|
261
|
+
d.month.should == 1
|
262
|
+
d.day.should == 10
|
263
|
+
|
264
|
+
|
265
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007 01:02:03")
|
266
|
+
d.year.should == 2007
|
267
|
+
d.month.should == 1
|
268
|
+
d.day.should == 10
|
269
|
+
d.hour.should == 1
|
270
|
+
d.min.should == 2
|
271
|
+
d.sec.should == 3
|
272
|
+
end
|
273
|
+
|
274
|
+
it "parses a YY#{@sep}MM#{@sep}DD string into a DateTime object using the year digits as 20XX" do
|
275
|
+
d = DateTime.parse("10#{@sep}01#{@sep}07")
|
276
|
+
d.year.should == 2010
|
277
|
+
d.month.should == 1
|
278
|
+
d.day.should == 7
|
279
|
+
|
280
|
+
d = DateTime.parse("10#{@sep}01#{@sep}07 01:02:03 Z")
|
281
|
+
d.year.should == 2010
|
282
|
+
d.month.should == 1
|
283
|
+
d.day.should == 7
|
284
|
+
d.hour.should == 1
|
285
|
+
d.min.should == 2
|
286
|
+
d.sec.should == 3
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe :date_parse_eu, :shared => true do
|
292
|
+
# The - separator let's it work like European format, so it as a different spec
|
293
|
+
it "can parse a YYYY-MM-DD string into a DateTime object" do
|
294
|
+
d = DateTime.parse("2007#{@sep}10#{@sep}01")
|
295
|
+
d.year.should == 2007
|
296
|
+
d.month.should == 10
|
297
|
+
d.day.should == 1
|
298
|
+
|
299
|
+
d = DateTime.parse("2007#{@sep}10#{@sep}01 01:02:03Z")
|
300
|
+
d.year.should == 2007
|
301
|
+
d.month.should == 10
|
302
|
+
d.day.should == 1
|
303
|
+
d.hour.should == 1
|
304
|
+
d.min.should == 2
|
305
|
+
d.sec.should == 3
|
306
|
+
end
|
307
|
+
|
308
|
+
it "can parse a DD-MM-YYYY string into a DateTime object" do
|
309
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007")
|
310
|
+
d.year.should == 2007
|
311
|
+
d.month.should == 1
|
312
|
+
d.day.should == 10
|
313
|
+
|
314
|
+
d = DateTime.parse("10#{@sep}01#{@sep}2007 01:02:03-01:00")
|
315
|
+
d.year.should == 2007
|
316
|
+
d.month.should == 1
|
317
|
+
d.day.should == 10
|
318
|
+
d.hour.should == 1
|
319
|
+
d.min.should == 2
|
320
|
+
d.sec.should == 3
|
321
|
+
d.offset.should == -1/24.0
|
322
|
+
end
|
323
|
+
|
324
|
+
it "can parse a YY-MM-DD string into a DateTime object" do
|
325
|
+
d = DateTime.parse("10#{@sep}01#{@sep}07")
|
326
|
+
d.year.should == 2010
|
327
|
+
d.month.should == 1
|
328
|
+
d.day.should == 7
|
329
|
+
|
330
|
+
d = DateTime.parse("97#{@sep}01#{@sep}07 01:02:03+01:00")
|
331
|
+
d.year.should == 1997
|
332
|
+
d.month.should == 1
|
333
|
+
d.day.should == 7
|
334
|
+
d.hour.should == 1
|
335
|
+
d.min.should == 2
|
336
|
+
d.sec.should == 3
|
337
|
+
d.offset.should == 1/24.0
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
describe "DateTime#parse with '.' separator" do
|
343
|
+
before :all do
|
344
|
+
@sep = '.'
|
345
|
+
end
|
346
|
+
|
347
|
+
it_should_behave_like "date_parse"
|
348
|
+
end
|
349
|
+
|
350
|
+
describe "DateTime#parse with '/' separator" do
|
351
|
+
before :all do
|
352
|
+
@sep = '/'
|
353
|
+
end
|
354
|
+
|
355
|
+
it_should_behave_like "date_parse"
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "DateTime#parse with ' ' separator" do
|
359
|
+
before :all do
|
360
|
+
@sep = ' '
|
361
|
+
end
|
362
|
+
|
363
|
+
it_should_behave_like "date_parse"
|
364
|
+
end
|
365
|
+
|
366
|
+
describe "DateTime#parse with '/' separator US-style" do
|
367
|
+
before :all do
|
368
|
+
@sep = '/'
|
369
|
+
end
|
370
|
+
|
371
|
+
it_should_behave_like "date_parse_us"
|
372
|
+
end
|
373
|
+
|
374
|
+
ruby_version_is "" ... "1.8.7" do
|
375
|
+
describe "DateTime#parse with '.' separator US-style" do
|
376
|
+
before :all do
|
377
|
+
@sep = '.'
|
378
|
+
end
|
379
|
+
|
380
|
+
it_should_behave_like "date_parse_us"
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
describe "DateTime#parse with '-' separator EU-style" do
|
385
|
+
before :all do
|
386
|
+
@sep = '-'
|
387
|
+
end
|
388
|
+
|
389
|
+
it_should_behave_like "date_parse_eu"
|
390
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "DateTime parsing methods" do
|
5
|
+
it "._httpdate should parse an HTTP format" do
|
6
|
+
DateTime._httpdate("Fri, 02 Jan 2009 03:04:05 GMT").should ==
|
7
|
+
{:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>3, :min=>4, :sec=>5, :offset=>0, :zone=>'GMT'}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "._iso8601 should parse an ISO8601 format" do
|
11
|
+
DateTime._iso8601("2009-01-02T03:04:05+12:00").should == {:year=>2009, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
12
|
+
end
|
13
|
+
|
14
|
+
it "._jisx03010 should parse an JIS X 0301 format" do
|
15
|
+
DateTime._jisx0301("H21.01.02T03:04:05+12:00").should == {:year=>2009, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
16
|
+
DateTime._jisx0301("S63.01.02T03:04:05+12:00").should == {:year=>1988, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
17
|
+
DateTime._jisx0301("T14.01.02T03:04:05+12:00").should == {:year=>1925, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
18
|
+
DateTime._jisx0301("M44.01.02T03:04:05+12:00").should == {:year=>1911, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
19
|
+
DateTime._jisx0301("M06.01.02T03:04:05+12:00").should == {:year=>1873, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
20
|
+
DateTime._jisx0301("1872-01-02T03:04:05+12:00").should == {:year=>1872, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
21
|
+
DateTime._jisx0301("1867-01-02T03:04:05+12:00").should == {:year=>1867, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "._rfc2822 should parse an RFC2822 format" do
|
25
|
+
DateTime._rfc2822("Fri, 2 Jan 2009 03:04:05 +1200").should ==
|
26
|
+
{:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+1200'}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "._rfc822 should parse an RFC822 format" do
|
30
|
+
DateTime._rfc822("Fri, 2 Jan 2009 03:04:05 +1200").should ==
|
31
|
+
{:year=>2009, :mon=>1, :mday=>2, :wday=>5, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+1200'}
|
32
|
+
end
|
33
|
+
|
34
|
+
it "._rfc3339 should parse an RFC3339 format" do
|
35
|
+
DateTime._rfc3339("2009-01-02T03:04:05+12:00").should ==
|
36
|
+
{:year=>2009, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "._xmlschema should parse an ISO8601 format" do
|
40
|
+
DateTime._xmlschema("2009-01-02T03:04:05+12:00").should == {:year=>2009, :mon=>1, :mday=>2, :hour=>3, :min=>4, :sec=>5, :offset=>43200, :zone=>'+12:00'}
|
41
|
+
end
|
42
|
+
|
43
|
+
it ".httpdate should parse an HTTP format" do
|
44
|
+
DateTime.httpdate("Fri, 02 Jan 2009 03:04:05 GMT").should == DateTime.new(2009, 1, 2, 3, 4, 5)
|
45
|
+
end
|
46
|
+
|
47
|
+
it ".iso8601 should parse an ISO8601 format" do
|
48
|
+
DateTime.iso8601("2009-01-02T03:04:05+12:00").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
49
|
+
end
|
50
|
+
|
51
|
+
it ".jisx03010 should parse an JIS X 0301 format" do
|
52
|
+
DateTime.jisx0301("H21.01.02T03:04:05+12:00").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
53
|
+
DateTime.jisx0301("S63.01.02T03:04:05+12:00").should == DateTime.new(1988, 1, 2, 3, 4, 5, 0.5)
|
54
|
+
DateTime.jisx0301("T14.01.02T03:04:05+12:00").should == DateTime.new(1925, 1, 2, 3, 4, 5, 0.5)
|
55
|
+
DateTime.jisx0301("M44.01.02T03:04:05+12:00").should == DateTime.new(1911, 1, 2, 3, 4, 5, 0.5)
|
56
|
+
DateTime.jisx0301("M06.01.02T03:04:05+12:00").should == DateTime.new(1873, 1, 2, 3, 4, 5, 0.5)
|
57
|
+
DateTime.jisx0301("1872-01-02T03:04:05+12:00").should == DateTime.new(1872, 1, 2, 3, 4, 5, 0.5)
|
58
|
+
DateTime.jisx0301("1867-01-02T03:04:05+12:00").should == DateTime.new(1867, 1, 2, 3, 4, 5, 0.5)
|
59
|
+
end
|
60
|
+
|
61
|
+
it ".rfc2822 should parse an RFC2822 format" do
|
62
|
+
DateTime.rfc2822("Fri, 2 Jan 2009 03:04:05 +1200").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
63
|
+
end
|
64
|
+
|
65
|
+
it ".rfc822 should parse an RFC822 format" do
|
66
|
+
DateTime.rfc822("Fri, 2 Jan 2009 03:04:05 +1200").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
67
|
+
end
|
68
|
+
|
69
|
+
it ".rfc3339 should parse an RFC3339 format" do
|
70
|
+
DateTime.rfc3339("2009-01-02T03:04:05+12:00").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
71
|
+
end
|
72
|
+
|
73
|
+
it ".xmlschema should parse an ISO8601 format" do
|
74
|
+
DateTime.xmlschema("2009-01-02T03:04:05+12:00").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|