iso8601 0.12.2 → 0.12.3

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.
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Days do
4
+ describe 'Atomic' do
5
+ let(:subject) { ISO8601::Days.new(1) }
6
+
7
+ it "should respond to the Atomic interface" do
8
+ expect(subject).to respond_to(:factor)
9
+ expect(subject).to respond_to(:to_seconds)
10
+ expect(subject).to respond_to(:symbol)
11
+ expect(subject).to respond_to(:to_i)
12
+ expect(subject).to respond_to(:to_f)
13
+ expect(subject).to respond_to(:to_s)
14
+ expect(subject).to respond_to(:value)
15
+ expect(subject).to respond_to(:<=>)
16
+ expect(subject).to respond_to(:eql?)
17
+ expect(subject).to respond_to(:hash)
18
+ expect(subject).to respond_to(:valid_atom?)
19
+ end
20
+ end
21
+
22
+ describe '#factor' do
23
+ it "should return the Day factor" do
24
+ expect(ISO8601::Days.new(2).factor).to eq(86400)
25
+ end
26
+
27
+ it "should return the amount of seconds" do
28
+ expect(ISO8601::Days.new(2).to_seconds).to eq(172800)
29
+ expect(ISO8601::Days.new(-2).to_seconds).to eq(-172800)
30
+ end
31
+ end
32
+
33
+ describe '#symbol' do
34
+ it "should return the ISO symbol" do
35
+ expect(ISO8601::Days.new(1).symbol).to eq(:D)
36
+ end
37
+ end
38
+
39
+ describe '#hash' do
40
+ it "should build hash identity by value" do
41
+ expect(ISO8601::Days.new(3).hash).to eq(ISO8601::Days.new(3).hash)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,299 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Duration do
4
+ let(:common_year) { ISO8601::DateTime.new('2010-01-01') }
5
+ let(:leap_year) { ISO8601::DateTime.new('2000-01-01') }
6
+
7
+ let(:common_february) { ISO8601::DateTime.new('2010-02-01') }
8
+ let(:leap_february) { ISO8601::DateTime.new('2000-02-01') }
9
+
10
+ let(:common_november) { ISO8601::DateTime.new('2010-11-01') }
11
+ let(:common_december) { ISO8601::DateTime.new('2010-12-01') }
12
+
13
+ it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
14
+ expect { ISO8601::Duration.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
15
+ expect { ISO8601::Duration.new('P') }.to raise_error(ISO8601::Errors::UnknownPattern)
16
+ expect { ISO8601::Duration.new('PT') }.to raise_error(ISO8601::Errors::UnknownPattern)
17
+ expect { ISO8601::Duration.new('P1YT') }.to raise_error(ISO8601::Errors::UnknownPattern)
18
+ expect { ISO8601::Duration.new('T') }.to raise_error(ISO8601::Errors::UnknownPattern)
19
+ expect { ISO8601::Duration.new('PW') }.to raise_error(ISO8601::Errors::UnknownPattern)
20
+ expect { ISO8601::Duration.new('P1Y1W') }.to raise_error(ISO8601::Errors::UnknownPattern)
21
+ expect { ISO8601::Duration.new('~P1Y') }.to raise_error(ISO8601::Errors::UnknownPattern)
22
+ expect { ISO8601::Duration.new('.P1Y') }.to raise_error(ISO8601::Errors::UnknownPattern)
23
+ end
24
+
25
+ it "should raise a ISO8601::Errors::InvalidFraction for any invalid patterns" do
26
+ expect { ISO8601::Duration.new('PT10.5M10.5S') }.to raise_error(ISO8601::Errors::InvalidFractions)
27
+ end
28
+
29
+ it "should parse any allowed pattern" do
30
+ expect { ISO8601::Duration.new('P1Y') }.to_not raise_error
31
+ expect { ISO8601::Duration.new('P1Y1M') }.to_not raise_error
32
+ expect { ISO8601::Duration.new('P1Y1M1D') }.to_not raise_error
33
+ expect { ISO8601::Duration.new('P1Y1M1DT1H') }.to_not raise_error
34
+ expect { ISO8601::Duration.new('P1Y1M1DT0.5H') }.to_not raise_error
35
+ expect { ISO8601::Duration.new('P1Y1M1DT0,5H') }.to_not raise_error
36
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M') }.to_not raise_error
37
+ expect { ISO8601::Duration.new('P1Y1M1DT1H0.5M') }.to_not raise_error
38
+ expect { ISO8601::Duration.new('P1Y1M1DT1H0,5M') }.to_not raise_error
39
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S') }.to_not raise_error
40
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1.0S') }.to_not raise_error
41
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1,0S') }.to_not raise_error
42
+ expect { ISO8601::Duration.new('P1W') }.to_not raise_error
43
+ expect { ISO8601::Duration.new('+P1Y') }.to_not raise_error
44
+ expect { ISO8601::Duration.new('-P1Y') }.to_not raise_error
45
+ end
46
+
47
+ it "should raise a TypeError when the base is not a ISO8601::DateTime" do
48
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds(common_year) }.to_not raise_error
49
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds('2010-01-01') }.to raise_error(ISO8601::Errors::TypeError)
50
+ expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds(2010) }.to raise_error(ISO8601::Errors::TypeError)
51
+ end
52
+
53
+ describe '#pattern' do
54
+ it "should return the duration pattern" do
55
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').pattern).to eq('P1Y1M1DT1H1M1S')
56
+ expect(ISO8601::Duration.new(60).pattern).to eq('PT60S')
57
+ expect(ISO8601::Duration.new(-60).pattern).to eq('-PT60S')
58
+ end
59
+ end
60
+
61
+ describe '#to_s' do
62
+ it "should return the duration as a string" do
63
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_s).to eq('P1Y1M1DT1H1M1S')
64
+ end
65
+ end
66
+
67
+ describe '#+' do
68
+ it "should return the result of the addition" do
69
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + ISO8601::Duration.new('P1Y1M1DT1H1M1S')).to_s).to eq('P12Y2M2DT2H2M2S')
70
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M11S')
71
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
72
+ end
73
+
74
+ it "should perform addition operation with Numeric class" do
75
+ day = 60 * 60 * 24
76
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + day).to_s).to eq('P11Y1M2DT1H1M1S')
77
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + (2 * day).to_f).to_s).to eq('P11Y1M3DT1H1M1S')
78
+ end
79
+
80
+ it "should raise ISO8601::Errors::TypeError when other object is not Numeric or ISO8601::Duration" do
81
+ expect { ISO8601::Duration.new('PT1H') + 'wololo' }.to raise_error(ISO8601::Errors::TypeError)
82
+ end
83
+ end
84
+
85
+ describe '#-' do
86
+ it "should return the result of the subtraction" do
87
+ expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') - ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
88
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M1S')
89
+ expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('P1Y1M1DT1H1M11S')).to_s).to eq('PT0S')
90
+ expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT12S')).to_s).to eq('PT0S')
91
+ expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT1S')).to_s).to eq('PT11S')
92
+ expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('PT12S')).to_s).to eq('-PT11S')
93
+ expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('-PT12S')).to_s).to eq('PT13S')
94
+ end
95
+
96
+ it "should perform subtract operation with Numeric class" do
97
+ day = 60 * 60 * 24
98
+ minute = 60
99
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') - day).to_s).to eq('P11Y1MT1H1M1S')
100
+ expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') - (2 * minute).to_f).to_s).to eq('P11Y1M1DT59M1S')
101
+ end
102
+ end
103
+
104
+ describe '#to_seconds' do
105
+ context 'positive durations' do
106
+ it "should return the seconds of a P[n]Y duration in a common year" do
107
+ expect(ISO8601::Duration.new('P2Y').to_seconds(common_year)).to eq(Time.utc(2012, 1) - Time.utc(2010, 1))
108
+ end
109
+
110
+ it "should return the seconds of a P[n]Y duration in a leap year" do
111
+ expect(ISO8601::Duration.new('P2Y').to_seconds(leap_year)).to eq(Time.utc(2002, 1) - Time.utc(2000, 1))
112
+ end
113
+
114
+ it "should return the seconds of a P[n]Y[n]M duration in a common year" do
115
+ expect(ISO8601::Duration.new('P2Y3M').to_seconds(common_year)).to eq(Time.utc(2012, 4) - Time.utc(2010, 1))
116
+ end
117
+
118
+ it "should return the seconds of a P[n]Y[n]M duration in a leap year" do
119
+ expect(ISO8601::Duration.new('P2Y3M').to_seconds(leap_year)).to eq(Time.utc(2002, 4) - Time.utc(2000, 1))
120
+ end
121
+
122
+ it "should return the seconds of a P[n]M duration in a common year" do
123
+ expect(ISO8601::Duration.new('P1M').to_seconds(common_year)).to eq(2678400)
124
+ expect(ISO8601::Duration.new('P19M').to_seconds(ISO8601::DateTime.new('2012-05-01'))).to eq(Time.utc(2014, 12) - Time.utc(2012, 5))
125
+ expect(ISO8601::Duration.new('P14M').to_seconds(common_year)).to eq(Time.utc(2011, 3) - Time.utc(2010, 1))
126
+ expect(ISO8601::Duration.new('P1M').to_seconds(common_november)).to eq(Time.utc(2010, 12) - Time.utc(2010, 11))
127
+ expect(ISO8601::Duration.new('P1M').to_seconds(common_december)).to eq(Time.utc(2011, 1) - Time.utc(2010, 12))
128
+ expect(ISO8601::Duration.new('P2M').to_seconds(common_november)).to eq(Time.utc(2011, 1) - Time.utc(2010, 11))
129
+ expect(ISO8601::Duration.new('P3M').to_seconds(common_november)).to eq(Time.utc(2011, 2) - Time.utc(2010, 11))
130
+ end
131
+
132
+ it "should return the seconds of a P[n]M duration in a leap year" do
133
+ expect(ISO8601::Duration.new('P1M').to_seconds(leap_year)).to eq(Time.utc(2000, 2) - Time.utc(2000, 1))
134
+ expect(ISO8601::Duration.new('P2M').to_seconds(leap_year)).to eq(Time.utc(2000, 3) - Time.utc(2000, 1))
135
+ expect(ISO8601::Duration.new('P14M').to_seconds(leap_year)).to eq(Time.utc(2001, 3) - Time.utc(2000, 1))
136
+ end
137
+
138
+ it "should return the seconds of a P[n]Y[n]M[n]D duration" do
139
+ expect(ISO8601::Duration.new('P2Y11D').to_seconds(common_year)).to eq(Time.utc(2012, 1, 12) - Time.utc(2010, 1))
140
+ expect(ISO8601::Duration.new('P1Y1M1D').to_seconds(ISO8601::DateTime.new('2010-05-01'))).to eq(Time.utc(2011, 6, 2) - Time.utc(2010, 5))
141
+ end
142
+
143
+ it "should return the seconds of a P[n]D duration" do
144
+ expect(ISO8601::Duration.new('P1D').to_seconds(common_year)).to eq(Time.utc(2010, 1, 2) - Time.utc(2010, 1, 1))
145
+ expect(ISO8601::Duration.new('P11D').to_seconds(common_year)).to eq(Time.utc(2010, 1, 12) - Time.utc(2010, 1, 1))
146
+ expect(ISO8601::Duration.new('P3M11D').to_seconds(common_year)).to eq(Time.utc(2010, 4, 12) - Time.utc(2010, 1))
147
+ end
148
+
149
+ it "should return the seconds of a P[n]W duration" do
150
+ expect(ISO8601::Duration.new('P2W').to_seconds).to eq(1209600)
151
+ end
152
+
153
+ it "should return the seconds of a PT[n]H duration" do
154
+ expect(ISO8601::Duration.new('PT5H').to_seconds).to eq(18000)
155
+ expect(ISO8601::Duration.new('P1YT5H').to_seconds(common_year)).to eq(Time.utc(2011, 1, 1, 5) - Time.utc(2010, 1))
156
+ end
157
+
158
+ it "should return the seconds of a PT[n]H[n]M duration" do
159
+ expect(ISO8601::Duration.new('PT5M').to_seconds).to eq(60 * 5)
160
+ expect(ISO8601::Duration.new('PT1H5M').to_seconds).to eq(3900)
161
+ end
162
+
163
+ it "should return the seconds of a PT[n]H[n]M duration" do
164
+ expect(ISO8601::Duration.new('PT10S').to_seconds).to eq(10)
165
+ expect(ISO8601::Duration.new('PT10.4S').to_seconds).to eq(10.4)
166
+ end
167
+ end
168
+
169
+ context 'negative durations' do
170
+ it "should return the seconds of a -P[n]Y duration" do
171
+ expect(ISO8601::Duration.new('-P2Y').to_seconds(common_year)).to eq(Time.utc(2008, 1) - Time.utc(2010, 1))
172
+ end
173
+
174
+ it "should return the seconds of a -P[n]Y duration in a leap year" do
175
+ expect(ISO8601::Duration.new('-P2Y').to_seconds(ISO8601::DateTime.new('2001-01-01'))).to eq(Time.utc(1999, 1) - Time.utc(2001, 1))
176
+ end
177
+
178
+ it "should return the seconds of a -P[n]Y[n]M duration in a common year" do
179
+ expect(ISO8601::Duration.new('-P2Y3M').to_seconds(ISO8601::DateTime.new('2010-01-01'))).to eq(Time.utc(2007, 10) - Time.utc(2010, 1))
180
+ end
181
+
182
+ it "should return the seconds of a -P[n]Y[n]M duration in a leap year" do
183
+ expect(ISO8601::Duration.new('-P2Y3M').to_seconds(ISO8601::DateTime.new('2001-01-01'))).to eq(Time.utc(1998, 10) - Time.utc(2001, 1))
184
+ end
185
+
186
+ it "should return the seconds of a -P[n]M duration in a common year" do
187
+ expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2012-01-01'))).to eq(Time.utc(2011, 12) - Time.utc(2012, 1))
188
+ expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2012-02-01'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 2))
189
+ expect(ISO8601::Duration.new('-P2M').to_seconds(ISO8601::DateTime.new('2012-03-01'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 3))
190
+ expect(ISO8601::Duration.new('-P36M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2010, 3) - Time.utc(2013, 3))
191
+ expect(ISO8601::Duration.new('-P39M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2009, 12) - Time.utc(2013, 3))
192
+ expect(ISO8601::Duration.new('-P156M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2000, 3) - Time.utc(2013, 3))
193
+ end
194
+
195
+ it "should return the seconds of a -P[n]M duration in a leap year" do
196
+ expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2000-02-01'))).to eq(Time.utc(2000, 1) - Time.utc(2000, 2))
197
+ expect(ISO8601::Duration.new('-P2M').to_seconds(ISO8601::DateTime.new('2000-03-01'))).to eq(Time.utc(2000, 1) - Time.utc(2000, 3))
198
+ expect(ISO8601::Duration.new('-P14M').to_seconds(ISO8601::DateTime.new('2001-03-01'))).to eq(Time.utc(2000, 1) - Time.utc(2001, 3))
199
+ end
200
+
201
+ it "should return the seconds of a -P[n]Y[n]M[n]D duration" do
202
+ expect(ISO8601::Duration.new('-P2Y11D').to_seconds(ISO8601::DateTime.new('2014-01-12'))).to eq(Time.utc(2012, 1) - Time.utc(2014, 1, 12))
203
+ expect(ISO8601::Duration.new('-P1Y1M1D').to_seconds(ISO8601::DateTime.new('2010-05-01'))).to eq(Time.utc(2009, 3, 31) - Time.utc(2010, 5))
204
+ end
205
+
206
+ it "should return the seconds of a -P[n]D duration" do
207
+ expect(ISO8601::Duration.new('-P1D').to_seconds(ISO8601::DateTime.new('2012-01-02'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 2))
208
+ expect(ISO8601::Duration.new('-P11D').to_seconds(ISO8601::DateTime.new('2012-01-12'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 12))
209
+ expect(ISO8601::Duration.new('-P3M11D').to_seconds(ISO8601::DateTime.new('2012-04-12'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 4, 12))
210
+ end
211
+
212
+ it "should return the seconds of a -P[n]W duration" do
213
+ expect(ISO8601::Duration.new('-P2W').to_seconds).to eq(-1209600)
214
+ end
215
+
216
+ it "should return the seconds of a -PT[n]H duration" do
217
+ expect(ISO8601::Duration.new('-PT5H').to_seconds(ISO8601::DateTime.new('2012-01-01T05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 5))
218
+ expect(ISO8601::Duration.new('-P1YT5H').to_seconds(ISO8601::DateTime.new('2013-01-01T05'))).to eq(Time.utc(2012, 1) - Time.utc(2013, 1, 1, 5))
219
+ end
220
+
221
+ it "should return the seconds of a -PT[n]H[n]M duration" do
222
+ expect(ISO8601::Duration.new('-PT5M').to_seconds(ISO8601::DateTime.new('2012-01-01T00:05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 0, 5))
223
+ expect(ISO8601::Duration.new('-PT1H5M').to_seconds(ISO8601::DateTime.new('2012-01-01T01:05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 1, 5))
224
+ expect(ISO8601::Duration.new('-PT1H5M').to_seconds(common_year)).to eq(ISO8601::Duration.new('-PT65M').to_seconds(common_year))
225
+ end
226
+
227
+ it "should return the seconds of a -PT[n]H[n]M duration" do
228
+ expect(ISO8601::Duration.new('-PT10S').to_seconds(ISO8601::DateTime.new('2012-01-01T00:00:00'))).to eq(Time.utc(2011, 12, 31, 23, 59, 50) - Time.utc(2012, 1))
229
+ expect(ISO8601::Duration.new('-PT10.4S').to_seconds).to eq(-10.4)
230
+ expect(ISO8601::Duration.new('-PT10,4S').to_seconds).to eq(-10.4)
231
+ end
232
+ end
233
+ end
234
+
235
+ describe '#abs' do
236
+ let(:positive) { ISO8601::Duration.new('PT1H') }
237
+ let(:negative) { ISO8601::Duration.new('-PT1H') }
238
+
239
+ it "should return a kind of duration" do
240
+ expect(negative.abs).to be_instance_of(ISO8601::Duration)
241
+ end
242
+
243
+ it "should return the absolute value of the duration" do
244
+ expect(negative.abs).to eq(positive)
245
+ end
246
+ end
247
+
248
+ describe '#==' do
249
+ it "should equal by computed value" do
250
+ expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT1H')).to be_truthy
251
+ expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT60M')).to be_truthy
252
+ end
253
+
254
+ it "should equal by a Numeric value" do
255
+ hour = 60 * 60
256
+ expect(ISO8601::Duration.new('PT1H') == hour).to be_truthy
257
+ expect(ISO8601::Duration.new('PT2H') == hour).to be_falsy
258
+ end
259
+ end
260
+
261
+ describe '#-@' do
262
+ let(:positive) { ISO8601::Duration.new('PT1H') }
263
+ let(:negative) { ISO8601::Duration.new('-PT1H') }
264
+
265
+ it "should return a kind of duration" do
266
+ expect(-negative).to be_instance_of(ISO8601::Duration)
267
+ end
268
+
269
+ it "should return the negation of a positive duration" do
270
+ expect(-positive).to eq(negative)
271
+ end
272
+
273
+ it "should return the negation of a negative duration" do
274
+ expect(-negative).to eq(positive)
275
+ end
276
+ end
277
+
278
+ describe '#eql?' do
279
+ it "should respond to #eql?" do
280
+ subject = ISO8601::Duration.new('PT1H')
281
+ expect(subject).to respond_to(:eql?)
282
+ end
283
+
284
+ it "should equal by hash identity" do
285
+ expect(ISO8601::Duration.new('PT1H').eql?(ISO8601::Duration.new('PT1H'))).to be_truthy
286
+ expect(ISO8601::Duration.new('PT1H').eql?(ISO8601::Duration.new('PT60M'))).to be_falsy
287
+ end
288
+ end
289
+
290
+ describe '#hash' do
291
+ it "should respond to #hash" do
292
+ expect(ISO8601::Duration.new('PT1H')).to respond_to(:hash)
293
+ end
294
+
295
+ it "should build hash identity by value" do
296
+ expect(ISO8601::Duration.new('PT1H').hash).to eq(ISO8601::Duration.new('PT1H').hash)
297
+ end
298
+ end
299
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Hours do
4
+ describe 'Atomic' do
5
+ let(:subject) { ISO8601::Hours.new(1) }
6
+
7
+ it "should respond to the Atomic interface" do
8
+ %i[factor
9
+ to_seconds
10
+ symbol
11
+ to_i
12
+ to_f
13
+ to_s
14
+ value
15
+ <=>
16
+ eql?
17
+ hash
18
+ valid_atom?].each { |m| expect(subject).to respond_to(m) }
19
+ end
20
+ end
21
+
22
+ describe '#factor' do
23
+ it "should return the Hour factor" do
24
+ expect(ISO8601::Hours.new(2).factor).to eq(3600)
25
+ end
26
+
27
+ it "should return the amount of seconds" do
28
+ expect(ISO8601::Hours.new(2).to_seconds).to eq(7200)
29
+ expect(ISO8601::Hours.new(-2).to_seconds).to eq(-7200)
30
+ end
31
+ end
32
+
33
+ describe '#symbol' do
34
+ it "should return the ISO symbol" do
35
+ expect(ISO8601::Hours.new(1).symbol).to eq(:H)
36
+ end
37
+ end
38
+
39
+ describe '#hash' do
40
+ it "should build hash identity by value" do
41
+ expect(ISO8601::Hours.new(3).hash).to eq(ISO8601::Hours.new(3).hash)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Minutes do
4
+ describe 'Atomic' do
5
+ let(:subject) { ISO8601::Minutes.new(1) }
6
+
7
+ it "should respond to the Atomic interface" do
8
+ %i[factor
9
+ to_seconds
10
+ symbol
11
+ to_i
12
+ to_f
13
+ to_s
14
+ value
15
+ <=>
16
+ eql?
17
+ hash
18
+ valid_atom?].each { |m| expect(subject).to respond_to(m) }
19
+ end
20
+ end
21
+
22
+ describe '#factor' do
23
+ it "should return the Minute factor" do
24
+ expect(ISO8601::Minutes.new(2).factor).to eq(60)
25
+ end
26
+
27
+ it "should return the amount of seconds" do
28
+ expect(ISO8601::Minutes.new(2).to_seconds).to eq(120)
29
+ expect(ISO8601::Minutes.new(-2).to_seconds).to eq(-120)
30
+ end
31
+ end
32
+
33
+ describe '#symbol' do
34
+ it "should return the ISO symbol" do
35
+ expect(ISO8601::Minutes.new(1).symbol).to eq(:M)
36
+ end
37
+ end
38
+
39
+ describe '#hash' do
40
+ it "should build hash identity by value" do
41
+ expect(ISO8601::Minutes.new(3).hash).to eq(ISO8601::Minutes.new(3).hash)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Months do
4
+ let(:common_year) { ISO8601::DateTime.new('2010-01-01') }
5
+ let(:leap_year) { ISO8601::DateTime.new('2000-01-01') }
6
+
7
+ let(:common_february) { ISO8601::DateTime.new('2010-02-01') }
8
+ let(:leap_february) { ISO8601::DateTime.new('2000-02-01') }
9
+
10
+ let(:common_november) { ISO8601::DateTime.new('2017-11-01') }
11
+
12
+ let(:common_december) { ISO8601::DateTime.new('2017-12-01') }
13
+ let(:leap_december) { ISO8601::DateTime.new('2000-12-01') }
14
+
15
+ describe 'Atomic' do
16
+ let(:subject) { ISO8601::Months.new(1) }
17
+
18
+ it "should respond to the Atomic interface" do
19
+ %i[factor
20
+ to_seconds
21
+ symbol
22
+ to_i
23
+ to_f
24
+ to_s
25
+ value
26
+ <=>
27
+ eql?
28
+ hash
29
+ valid_atom?].each { |m| expect(subject).to respond_to(m) }
30
+ end
31
+ end
32
+
33
+ describe '#factor' do
34
+ it "should return the Month factor" do
35
+ expect { ISO8601::Months.new(1).factor }.to_not raise_error
36
+ expect(ISO8601::Months.new(2).factor).to eq(2628000)
37
+ expect(ISO8601::Months.new(0).factor).to eq(2628000)
38
+ end
39
+
40
+ it "should return the Month factor for a common year" do
41
+ expect(ISO8601::Months.new(1).factor(common_year)).to eq(2678400)
42
+ end
43
+
44
+ it "should return the Month factor for a leap year" do
45
+ expect(ISO8601::Months.new(1).factor(leap_year)).to eq(2678400)
46
+ end
47
+
48
+ it "should return the Month factor based on february for a common year" do
49
+ expect(ISO8601::Months.new(1).factor(common_february)).to eq(2419200)
50
+ end
51
+
52
+ it "should return the Month factor based on february for a leap year" do
53
+ expect(ISO8601::Months.new(1).factor(leap_february)).to eq(2505600)
54
+ end
55
+ end
56
+
57
+ describe '#to_seconds' do
58
+ it "should return the amount of seconds" do
59
+ expect(ISO8601::Months.new(2).to_seconds).to eq(5256000)
60
+ end
61
+
62
+ it "should return the amount of seconds for a common year" do
63
+ expect(ISO8601::Months.new(2).to_seconds(common_year)).to eq(5097600)
64
+ expect(ISO8601::Months.new(1).to_seconds(common_year)).to eq(2678400)
65
+ expect(ISO8601::Months.new(0).to_seconds(common_year)).to eq(0)
66
+ expect(ISO8601::Months.new(0).to_seconds(common_december)).to eq(0)
67
+ expect(ISO8601::Months.new(2).to_seconds(common_november)).to eq(5270400)
68
+ expect(ISO8601::Months.new(1).to_seconds(common_november)).to eq(2592000)
69
+ expect(ISO8601::Months.new(0).to_seconds(common_november)).to eq(0)
70
+ end
71
+
72
+ it "should return the amount of seconds for a leap year" do
73
+ expect(ISO8601::Months.new(2).to_seconds(leap_year)).to eq(5184000)
74
+ end
75
+
76
+ it "should return the amount of seconds based on februrary for a common year" do
77
+ expect(ISO8601::Months.new(2).to_seconds(common_february)).to eq(5097600)
78
+ end
79
+
80
+ it "should return the amount of seconds based on february for a leap year" do
81
+ expect(ISO8601::Months.new(2).to_seconds(leap_february)).to eq(5184000)
82
+ expect(ISO8601::Months.new(12).to_seconds(leap_february)).to eq(31622400)
83
+ expect(ISO8601::Months.new(12).to_seconds(leap_february)).to eq(ISO8601::Years.new(1).to_seconds(leap_year))
84
+ end
85
+ end
86
+
87
+ describe '#symbol' do
88
+ it "should return the ISO symbol" do
89
+ expect(ISO8601::Months.new(1).symbol).to eq(:M)
90
+ end
91
+ end
92
+
93
+ describe '#hash' do
94
+ it "should build hash identity by value" do
95
+ expect(ISO8601::Months.new(3).hash).to eq(ISO8601::Months.new(3).hash)
96
+ end
97
+ end
98
+ end