iso8601 0.10.0 → 0.12.2

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