iso8601 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -5
- data/README.md +7 -7
- data/iso8601.gemspec +1 -1
- data/lib/iso8601.rb +1 -1
- data/lib/iso8601/atoms.rb +126 -28
- data/lib/iso8601/date.rb +23 -4
- data/lib/iso8601/{dateTime.rb → date_time.rb} +21 -1
- data/lib/iso8601/duration.rb +187 -110
- data/lib/iso8601/errors.rb +4 -0
- data/lib/iso8601/time.rb +20 -1
- data/lib/iso8601/version.rb +1 -1
- data/spec/iso8601/atoms_spec.rb +182 -46
- data/spec/iso8601/date_spec.rb +13 -16
- data/spec/iso8601/{dateTime_spec.rb → date_time_spec.rb} +30 -31
- data/spec/iso8601/duration_spec.rb +113 -84
- data/spec/iso8601/time_spec.rb +25 -21
- data/spec/spec_helper.rb +1 -1
- metadata +7 -7
data/lib/iso8601/errors.rb
CHANGED
data/lib/iso8601/time.rb
CHANGED
@@ -14,7 +14,7 @@ module ISO8601
|
|
14
14
|
|
15
15
|
def_delegators(:@time,
|
16
16
|
:to_time, :to_date, :to_datetime,
|
17
|
-
:hour, :minute, :zone
|
17
|
+
:hour, :minute, :zone)
|
18
18
|
##
|
19
19
|
# The separator used in the original ISO 8601 string.
|
20
20
|
attr_reader :separator
|
@@ -39,6 +39,25 @@ module ISO8601
|
|
39
39
|
@second = @time.second + @time.second_fraction.to_f
|
40
40
|
end
|
41
41
|
##
|
42
|
+
# @param [#hash] contrast The contrast to compare against
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
def ==(contrast)
|
46
|
+
(hash == contrast.hash)
|
47
|
+
end
|
48
|
+
##
|
49
|
+
# @param [#hash] contrast The contrast to compare against
|
50
|
+
#
|
51
|
+
# @return [Boolean]
|
52
|
+
def eql?(contrast)
|
53
|
+
(hash == contrast.hash)
|
54
|
+
end
|
55
|
+
##
|
56
|
+
# @return [Fixnum]
|
57
|
+
def hash
|
58
|
+
[atoms, self.class].hash
|
59
|
+
end
|
60
|
+
##
|
42
61
|
# Forwards the time the given amount of seconds.
|
43
62
|
#
|
44
63
|
# @param [Numeric] seconds The seconds to add
|
data/lib/iso8601/version.rb
CHANGED
data/spec/iso8601/atoms_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
|
-
describe ISO8601::Atom do
|
3
|
+
RSpec.describe ISO8601::Atom do
|
6
4
|
it "should raise a TypeError when receives anything but a Numeric value" do
|
7
5
|
expect { ISO8601::Atom.new('1') }.to raise_error
|
8
6
|
expect { ISO8601::Atom.new(true) }.to raise_error
|
@@ -20,16 +18,28 @@ describe ISO8601::Atom do
|
|
20
18
|
expect { ISO8601::Atom.new(1, 10) }.to raise_error
|
21
19
|
end
|
22
20
|
it "should create a new atom" do
|
23
|
-
ISO8601::Atom.new(-1).
|
21
|
+
expect(ISO8601::Atom.new(-1)).to be_an_instance_of(ISO8601::Atom)
|
24
22
|
end
|
25
23
|
describe '#to_i' do
|
26
24
|
it "should return an integer" do
|
27
|
-
ISO8601::Atom.new(1).to_i.
|
28
|
-
ISO8601::Atom.new(1.0).to_i.
|
25
|
+
expect(ISO8601::Atom.new(1).to_i).to be_a_kind_of(Integer)
|
26
|
+
expect(ISO8601::Atom.new(1.0).to_i).to be_a_kind_of(Integer)
|
29
27
|
end
|
30
28
|
it "should return the integer part of the given number" do
|
31
|
-
|
32
|
-
|
29
|
+
expect(ISO8601::Atom.new(1.0).to_i).to eq(1.0.to_i)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe '#to_f' do
|
33
|
+
it "should return a float" do
|
34
|
+
expect(ISO8601::Atom.new(1).to_f).to be_a_kind_of(Float)
|
35
|
+
expect(ISO8601::Atom.new(1.0).to_f).to be_a_kind_of(Float)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe '#value' do
|
39
|
+
it "should return the simplest value representation" do
|
40
|
+
expect(ISO8601::Atom.new(1).value).to eq(1)
|
41
|
+
expect(ISO8601::Atom.new(1.0).value).to eq(1)
|
42
|
+
expect(ISO8601::Atom.new(1.1).value).to eq(1.1)
|
33
43
|
end
|
34
44
|
end
|
35
45
|
describe '#factor' do
|
@@ -43,31 +53,50 @@ describe ISO8601::Years do
|
|
43
53
|
describe '#factor' do
|
44
54
|
it "should return the Year factor" do
|
45
55
|
expect { ISO8601::Years.new(1).factor }.to_not raise_error
|
46
|
-
ISO8601::Years.new(2).factor.
|
47
|
-
ISO8601::Years.new(1).factor.
|
56
|
+
expect(ISO8601::Years.new(2).factor).to eq(31536000)
|
57
|
+
expect(ISO8601::Years.new(1).factor).to eq(31536000)
|
48
58
|
end
|
49
59
|
it "should return the Year factor for a common year" do
|
50
|
-
ISO8601::Years.new(1, ISO8601::DateTime.new("2010-01-01")).factor.
|
60
|
+
expect(ISO8601::Years.new(1, ISO8601::DateTime.new("2010-01-01")).factor).to eq(31536000)
|
51
61
|
end
|
52
62
|
it "should return the Year factor for a leap year" do
|
53
|
-
ISO8601::Years.new(1, ISO8601::DateTime.new("2000-01-01")).factor.
|
63
|
+
expect(ISO8601::Years.new(1, ISO8601::DateTime.new("2000-01-01")).factor).to eq(31622400)
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
67
|
describe '#to_seconds' do
|
58
68
|
it "should return the amount of seconds" do
|
59
|
-
ISO8601::Years.new(2).to_seconds.
|
60
|
-
ISO8601::Years.new(-2).to_seconds.
|
69
|
+
expect(ISO8601::Years.new(2).to_seconds).to eq(63072000)
|
70
|
+
expect(ISO8601::Years.new(-2).to_seconds).to eq(-63072000)
|
61
71
|
end
|
62
72
|
it "should return the amount of seconds for a common year" do
|
63
73
|
base = ISO8601::DateTime.new('2010-01-01')
|
64
|
-
ISO8601::Years.new(2, base).to_seconds.
|
65
|
-
ISO8601::Years.new(12, base).to_seconds.
|
74
|
+
expect(ISO8601::Years.new(2, base).to_seconds).to eq(63072000)
|
75
|
+
expect(ISO8601::Years.new(12, base).to_seconds).to eq(378691200)
|
66
76
|
end
|
67
77
|
it "should return the amount of seconds for a leap year" do
|
68
78
|
base = ISO8601::DateTime.new('2000-01-01')
|
69
|
-
ISO8601::Years.new(2, base).to_seconds.
|
70
|
-
ISO8601::Years.new(15, base).to_seconds.
|
79
|
+
expect(ISO8601::Years.new(2, base).to_seconds).to eq(63158400)
|
80
|
+
expect(ISO8601::Years.new(15, base).to_seconds).to eq(473385600)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#symbol' do
|
85
|
+
it "should return the ISO symbol" do
|
86
|
+
expect(ISO8601::Years.new(1)).to respond_to(:symbol)
|
87
|
+
expect(ISO8601::Years.new(1).symbol).to eq(:Y)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#hash' do
|
92
|
+
let(:subject) { ISO8601::Years.new(3) }
|
93
|
+
it "should respond to #hash" do
|
94
|
+
expect(subject).to respond_to(:hash)
|
95
|
+
end
|
96
|
+
it "should build hash identity by value" do
|
97
|
+
contrast = ISO8601::Years.new(3)
|
98
|
+
|
99
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
71
100
|
end
|
72
101
|
end
|
73
102
|
end
|
@@ -76,38 +105,56 @@ describe ISO8601::Months do
|
|
76
105
|
describe '#factor' do
|
77
106
|
it "should return the Month factor" do
|
78
107
|
expect { ISO8601::Months.new(1).factor }.to_not raise_error
|
79
|
-
ISO8601::Months.new(2).factor.
|
108
|
+
expect(ISO8601::Months.new(2).factor).to eq(2628000)
|
80
109
|
end
|
81
110
|
it "should return the Month factor for a common year" do
|
82
|
-
ISO8601::Months.new(1, ISO8601::DateTime.new('2010-01-01')).factor.
|
111
|
+
expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2010-01-01')).factor).to eq(2678400)
|
83
112
|
end
|
84
113
|
it "should return the Month factor for a leap year" do
|
85
|
-
ISO8601::Months.new(1, ISO8601::DateTime.new('2000-01-01')).factor.
|
114
|
+
expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2000-01-01')).factor).to eq(2678400)
|
86
115
|
end
|
87
116
|
it "should return the Month factor based on february for a common year" do
|
88
|
-
ISO8601::Months.new(1, ISO8601::DateTime.new('2010-02-01')).factor.
|
117
|
+
expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2010-02-01')).factor).to eq(2419200)
|
89
118
|
end
|
90
119
|
it "should return the Month factor based on february for a leap year" do
|
91
|
-
ISO8601::Months.new(1, ISO8601::DateTime.new('2000-02-01')).factor.
|
120
|
+
expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2000-02-01')).factor).to eq(2505600)
|
92
121
|
end
|
93
122
|
end
|
94
123
|
describe '#to_seconds' do
|
95
124
|
it "should return the amount of seconds" do
|
96
|
-
ISO8601::Months.new(2).to_seconds.
|
125
|
+
expect(ISO8601::Months.new(2).to_seconds).to eq(5256000)
|
97
126
|
end
|
98
127
|
it "should return the amount of seconds for a common year" do
|
99
|
-
ISO8601::Months.new(2, ISO8601::DateTime.new('2010-01-01')).to_seconds.
|
128
|
+
expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(5097600)
|
100
129
|
end
|
101
130
|
it "should return the amount of seconds for a leap year" do
|
102
|
-
ISO8601::Months.new(2, ISO8601::DateTime.new('2000-01-01')).to_seconds.
|
131
|
+
expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(5184000)
|
103
132
|
end
|
104
133
|
it "should return the amount of seconds based on februrary for a common year" do
|
105
|
-
ISO8601::Months.new(2, ISO8601::DateTime.new('2010-02-01')).to_seconds.
|
134
|
+
expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2010-02-01')).to_seconds).to eq(5097600)
|
106
135
|
end
|
107
136
|
it "should return the amount of seconds based on february for a leap year" do
|
108
|
-
ISO8601::Months.new(2, ISO8601::DateTime.new('2000-02-01')).to_seconds.
|
109
|
-
ISO8601::Months.new(12, ISO8601::DateTime.new('2000-02-01')).to_seconds.
|
110
|
-
ISO8601::Months.new(12, ISO8601::DateTime.new('2000-02-01')).to_seconds.
|
137
|
+
expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(5184000)
|
138
|
+
expect(ISO8601::Months.new(12, ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(31622400)
|
139
|
+
expect(ISO8601::Months.new(12, ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(ISO8601::Years.new(1, ISO8601::DateTime.new("2000-02-01")).to_seconds)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
describe '#symbol' do
|
143
|
+
it "should return the ISO symbol" do
|
144
|
+
expect(ISO8601::Months.new(1)).to respond_to(:symbol)
|
145
|
+
expect(ISO8601::Months.new(1).symbol).to eq(:M)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#hash' do
|
150
|
+
let(:subject) { ISO8601::Months.new(3) }
|
151
|
+
it "should respond to #hash" do
|
152
|
+
expect(subject).to respond_to(:hash)
|
153
|
+
end
|
154
|
+
it "should build hash identity by value" do
|
155
|
+
contrast = ISO8601::Months.new(3)
|
156
|
+
|
157
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
111
158
|
end
|
112
159
|
end
|
113
160
|
end
|
@@ -115,13 +162,31 @@ end
|
|
115
162
|
describe ISO8601::Weeks do
|
116
163
|
describe '#factor' do
|
117
164
|
it "should return the Week factor" do
|
118
|
-
ISO8601::Weeks.new(2).factor.
|
165
|
+
expect(ISO8601::Weeks.new(2).factor).to eq(604800)
|
119
166
|
end
|
120
167
|
end
|
121
168
|
describe '#to_seconds' do
|
122
169
|
it "should return the amount of seconds" do
|
123
|
-
ISO8601::Weeks.new(2).to_seconds.
|
124
|
-
ISO8601::Weeks.new(-2).to_seconds.
|
170
|
+
expect(ISO8601::Weeks.new(2).to_seconds).to eq(1209600)
|
171
|
+
expect(ISO8601::Weeks.new(-2).to_seconds).to eq(-1209600)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
describe '#symbol' do
|
175
|
+
it "should return the ISO symbol" do
|
176
|
+
expect(ISO8601::Weeks.new(1)).to respond_to(:symbol)
|
177
|
+
expect(ISO8601::Weeks.new(1).symbol).to eq(:W)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe '#hash' do
|
182
|
+
let(:subject) { ISO8601::Weeks.new(3) }
|
183
|
+
it "should respond to #hash" do
|
184
|
+
expect(subject).to respond_to(:hash)
|
185
|
+
end
|
186
|
+
it "should build hash identity by value" do
|
187
|
+
contrast = ISO8601::Weeks.new(3)
|
188
|
+
|
189
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
125
190
|
end
|
126
191
|
end
|
127
192
|
end
|
@@ -129,11 +194,29 @@ end
|
|
129
194
|
describe ISO8601::Days do
|
130
195
|
describe '#factor' do
|
131
196
|
it "should return the Day factor" do
|
132
|
-
ISO8601::Days.new(2).factor.
|
197
|
+
expect(ISO8601::Days.new(2).factor).to eq(86400)
|
133
198
|
end
|
134
199
|
it "should return the amount of seconds" do
|
135
|
-
ISO8601::Days.new(2).to_seconds.
|
136
|
-
ISO8601::Days.new(-2).to_seconds.
|
200
|
+
expect(ISO8601::Days.new(2).to_seconds).to eq(172800)
|
201
|
+
expect(ISO8601::Days.new(-2).to_seconds).to eq(-172800)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
describe '#symbol' do
|
205
|
+
it "should return the ISO symbol" do
|
206
|
+
expect(ISO8601::Days.new(1)).to respond_to(:symbol)
|
207
|
+
expect(ISO8601::Days.new(1).symbol).to eq(:D)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#hash' do
|
212
|
+
let(:subject) { ISO8601::Days.new(3) }
|
213
|
+
it "should respond to #hash" do
|
214
|
+
expect(subject).to respond_to(:hash)
|
215
|
+
end
|
216
|
+
it "should build hash identity by value" do
|
217
|
+
contrast = ISO8601::Days.new(3)
|
218
|
+
|
219
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
137
220
|
end
|
138
221
|
end
|
139
222
|
end
|
@@ -141,11 +224,29 @@ end
|
|
141
224
|
describe ISO8601::Hours do
|
142
225
|
describe '#factor' do
|
143
226
|
it "should return the Hour factor" do
|
144
|
-
ISO8601::Hours.new(2).factor.
|
227
|
+
expect(ISO8601::Hours.new(2).factor).to eq(3600)
|
145
228
|
end
|
146
229
|
it "should return the amount of seconds" do
|
147
|
-
ISO8601::Hours.new(2).to_seconds.
|
148
|
-
ISO8601::Hours.new(-2).to_seconds.
|
230
|
+
expect(ISO8601::Hours.new(2).to_seconds).to eq(7200)
|
231
|
+
expect(ISO8601::Hours.new(-2).to_seconds).to eq(-7200)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
describe '#symbol' do
|
235
|
+
it "should return the ISO symbol" do
|
236
|
+
expect(ISO8601::Hours.new(1)).to respond_to(:symbol)
|
237
|
+
expect(ISO8601::Hours.new(1).symbol).to eq(:H)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#hash' do
|
242
|
+
let(:subject) { ISO8601::Hours.new(3) }
|
243
|
+
it "should respond to #hash" do
|
244
|
+
expect(subject).to respond_to(:hash)
|
245
|
+
end
|
246
|
+
it "should build hash identity by value" do
|
247
|
+
contrast = ISO8601::Hours.new(3)
|
248
|
+
|
249
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
149
250
|
end
|
150
251
|
end
|
151
252
|
end
|
@@ -153,11 +254,29 @@ end
|
|
153
254
|
describe ISO8601::Minutes do
|
154
255
|
describe '#factor' do
|
155
256
|
it "should return the Minute factor" do
|
156
|
-
ISO8601::Minutes.new(2).factor.
|
257
|
+
expect(ISO8601::Minutes.new(2).factor).to eq(60)
|
157
258
|
end
|
158
259
|
it "should return the amount of seconds" do
|
159
|
-
ISO8601::Minutes.new(2).to_seconds.
|
160
|
-
ISO8601::Minutes.new(-2).to_seconds.
|
260
|
+
expect(ISO8601::Minutes.new(2).to_seconds).to eq(120)
|
261
|
+
expect(ISO8601::Minutes.new(-2).to_seconds).to eq(-120)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
describe '#symbol' do
|
265
|
+
it "should return the ISO symbol" do
|
266
|
+
expect(ISO8601::Minutes.new(1)).to respond_to(:symbol)
|
267
|
+
expect(ISO8601::Minutes.new(1).symbol).to eq(:M)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe '#hash' do
|
272
|
+
let(:subject) { ISO8601::Minutes.new(3) }
|
273
|
+
it "should respond to #hash" do
|
274
|
+
expect(subject).to respond_to(:hash)
|
275
|
+
end
|
276
|
+
it "should build hash identity by value" do
|
277
|
+
contrast = ISO8601::Minutes.new(3)
|
278
|
+
|
279
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
161
280
|
end
|
162
281
|
end
|
163
282
|
end
|
@@ -165,12 +284,29 @@ end
|
|
165
284
|
describe ISO8601::Seconds do
|
166
285
|
describe '#factor' do
|
167
286
|
it "should return the Second factor" do
|
168
|
-
ISO8601::Seconds.new(2).factor.
|
287
|
+
expect(ISO8601::Seconds.new(2).factor).to eq(1)
|
169
288
|
end
|
170
289
|
it "should return the amount of seconds" do
|
171
|
-
ISO8601::Seconds.new(2).to_seconds.
|
172
|
-
ISO8601::Seconds.new(-2).to_seconds.
|
290
|
+
expect(ISO8601::Seconds.new(2).to_seconds).to eq(2)
|
291
|
+
expect(ISO8601::Seconds.new(-2).to_seconds).to eq(-2)
|
173
292
|
end
|
174
293
|
end
|
175
|
-
|
294
|
+
describe '#symbol' do
|
295
|
+
it "should return the ISO symbol" do
|
296
|
+
expect(ISO8601::Seconds.new(1)).to respond_to(:symbol)
|
297
|
+
expect(ISO8601::Seconds.new(1).symbol).to eq(:S)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
describe '#hash' do
|
302
|
+
let(:subject) { ISO8601::Seconds.new(3) }
|
303
|
+
it "should respond to #hash" do
|
304
|
+
expect(subject).to respond_to(:hash)
|
305
|
+
end
|
306
|
+
it "should build hash identity by value" do
|
307
|
+
contrast = ISO8601::Seconds.new(3)
|
176
308
|
|
309
|
+
expect(subject.hash == contrast.hash).to be_truthy
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
data/spec/iso8601/date_spec.rb
CHANGED
@@ -38,54 +38,51 @@ describe ISO8601::Date do
|
|
38
38
|
context 'reduced patterns' do
|
39
39
|
it "should parse correctly reduced dates" do
|
40
40
|
reduced_date = ISO8601::Date.new('20100509')
|
41
|
-
reduced_date.year.
|
42
|
-
reduced_date.month.
|
43
|
-
reduced_date.day.
|
41
|
+
expect(reduced_date.year).to eq(2010)
|
42
|
+
expect(reduced_date.month).to eq(5)
|
43
|
+
expect(reduced_date.day).to eq(9)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should return the right sign for the given year" do
|
48
|
-
ISO8601::Date.new('-2014-05-31').year.
|
49
|
-
ISO8601::Date.new('+2014-05-31').year.
|
48
|
+
expect(ISO8601::Date.new('-2014-05-31').year).to eq(-2014)
|
49
|
+
expect(ISO8601::Date.new('+2014-05-31').year).to eq(2014)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should respond to delegated casting methods" do
|
53
|
-
|
54
|
-
dt.should respond_to(:to_s, :to_time, :to_date, :to_datetime)
|
53
|
+
expect(ISO8601::Date.new('2014-12-11')).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
|
55
54
|
end
|
56
55
|
|
57
56
|
describe '#+' do
|
58
57
|
it "should return the result of the addition" do
|
59
|
-
(ISO8601::Date.new('2012-07-07') + 7).to_s.
|
58
|
+
expect((ISO8601::Date.new('2012-07-07') + 7).to_s).to eq('2012-07-14')
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
62
|
describe '#-' do
|
64
63
|
it "should return the result of the substraction" do
|
65
|
-
(ISO8601::Date.new('2012-07-07') - 7).to_s.
|
64
|
+
expect((ISO8601::Date.new('2012-07-07') - 7).to_s).to eq('2012-06-30')
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
68
|
describe '#to_a' do
|
70
69
|
it "should return an array of atoms" do
|
71
|
-
|
72
|
-
dt.should be_kind_of(Array)
|
73
|
-
dt.should == [2014, 5, 31]
|
70
|
+
expect(ISO8601::Date.new('2014-05-31').to_a).to eq([2014, 5, 31])
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
77
74
|
describe '#atoms' do
|
78
75
|
it "should return an array of original atoms" do
|
79
|
-
ISO8601::Date.new('2014-05-02').atoms.
|
80
|
-
ISO8601::Date.new('2014-05').atoms.
|
81
|
-
ISO8601::Date.new('2014').atoms.
|
76
|
+
expect(ISO8601::Date.new('2014-05-02').atoms).to eq([2014, 5, 2])
|
77
|
+
expect(ISO8601::Date.new('2014-05').atoms).to eq([2014, 5])
|
78
|
+
expect(ISO8601::Date.new('2014').atoms).to eq([2014])
|
82
79
|
end
|
83
80
|
end
|
84
81
|
|
85
82
|
describe '#hash' do
|
86
83
|
it "should return the date hash" do
|
87
84
|
subject = ISO8601::Date.new('2014-08-16')
|
88
|
-
contrast = ::Date.new(2014
|
85
|
+
contrast = ISO8601::Date.new('2014-08-16')
|
89
86
|
|
90
87
|
expect(subject).to respond_to(:hash)
|
91
88
|
expect(subject.hash).to eq(contrast.hash)
|