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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +13 -20
- data/iso8601.gemspec +7 -46
- data/lib/iso8601/date_time.rb +2 -2
- data/lib/iso8601/duration.rb +7 -0
- data/lib/iso8601/months.rb +2 -1
- data/lib/iso8601/version.rb +1 -1
- data/lib/iso8601/years.rb +2 -1
- metadata +15 -44
- data/CHANGELOG.md +0 -102
- data/Rakefile +0 -1
- data/docs/date-time.md +0 -86
- data/docs/duration.md +0 -76
- data/docs/time-interval.md +0 -120
- data/spec/iso8601/date_spec.rb +0 -91
- data/spec/iso8601/date_time_spec.rb +0 -154
- data/spec/iso8601/days_spec.rb +0 -44
- data/spec/iso8601/duration_spec.rb +0 -275
- data/spec/iso8601/hours_spec.rb +0 -44
- data/spec/iso8601/minutes_spec.rb +0 -44
- data/spec/iso8601/months_spec.rb +0 -94
- data/spec/iso8601/seconds_spec.rb +0 -44
- data/spec/iso8601/time_interval_spec.rb +0 -509
- data/spec/iso8601/time_spec.rb +0 -110
- data/spec/iso8601/weeks_spec.rb +0 -46
- data/spec/iso8601/years_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -12
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ISO8601::Seconds do
|
4
|
-
describe 'Atomic' do
|
5
|
-
let(:subject) { ISO8601::Seconds.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 Second factor" do
|
24
|
-
expect(ISO8601::Seconds.new(2).factor).to eq(1)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should return the amount of seconds" do
|
28
|
-
expect(ISO8601::Seconds.new(2).to_seconds).to eq(2)
|
29
|
-
expect(ISO8601::Seconds.new(-2).to_seconds).to eq(-2)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#symbol' do
|
34
|
-
it "should return the ISO symbol" do
|
35
|
-
expect(ISO8601::Seconds.new(1).symbol).to eq(:S)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#hash' do
|
40
|
-
it "should build hash identity by value" do
|
41
|
-
expect(ISO8601::Seconds.new(3).hash).to eq(ISO8601::Seconds.new(3).hash)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,509 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe ISO8601::TimeInterval do
|
4
|
-
describe 'pattern initialization' do
|
5
|
-
it "should raise a ISO8601::Errors::UnknownPattern if it not a valid interval pattern" do
|
6
|
-
# Invalid separators
|
7
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00ZP1Y2M10DT2H30M') }
|
8
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
9
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z-P1Y2M10D') }
|
10
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
11
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z~P1Y2M10D') }
|
12
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
13
|
-
expect { ISO8601::TimeInterval.parse('P1Y2M10DT2H30M2007-03-01T13:00:00Z') }
|
14
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
15
|
-
expect { ISO8601::TimeInterval.parse('P1Y2M10D-2007-03-01T13:00:00Z') }
|
16
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
17
|
-
expect { ISO8601::TimeInterval.parse('P1Y2M10D~2007-03-01T13:00:00Z') }
|
18
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
19
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z2008-05-11T15:30:00Z') }
|
20
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
21
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z-2008-05-11T15:30:00Z') }
|
22
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
23
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z~2008-05-11T15:30:00Z') }
|
24
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'with duration' do
|
28
|
-
it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
|
29
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/') }
|
30
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
31
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P') }
|
32
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
33
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT') }
|
34
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe 'with DateTimes' do
|
39
|
-
it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
|
40
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/2010-0-09') }
|
41
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
42
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/2010-05-09T103012+0400') }
|
43
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
44
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/2014-W15-02T10:11:12Z') }
|
45
|
-
.to raise_error(ISO8601::Errors::UnknownPattern)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should raise a ISO8601::Errors::UnknownPattern if start time and end time are durations" do
|
50
|
-
expect { ISO8601::TimeInterval.parse('P1Y2M10D/P1Y2M10D') }.to raise_error(ISO8601::Errors::UnknownPattern)
|
51
|
-
expect { ISO8601::TimeInterval.parse('P1Y0.5M/P1Y0.5M') }.to raise_error(ISO8601::Errors::UnknownPattern)
|
52
|
-
end
|
53
|
-
|
54
|
-
context "allowed patterns" do
|
55
|
-
it "should parse <start>/<duration>" do
|
56
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y') }.to_not raise_error
|
57
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1D') }.to_not raise_error
|
58
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1DT1H1M1.0S') }.to_not raise_error
|
59
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1DT1H1M1,0S') }.to_not raise_error
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should parse <duration>/<end>" do
|
63
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M1D/2010-05-09T10:30:12+04:00') }.to_not raise_error
|
64
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M1DT1H/-2014-05-31T16:26:00Z') }.to_not raise_error
|
65
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M1DT0.5H/2014-05-31T16:26:10.5Z') }.to_not raise_error
|
66
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M1DT0,5H/2014-05-31T16:26:10,5Z') }.to_not raise_error
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should parse <start>/<end>" do
|
70
|
-
expect { ISO8601::TimeInterval.parse('2014-001/2010-05-09T10:30') }.to_not raise_error
|
71
|
-
expect { ISO8601::TimeInterval.parse('2014121/2010-05-09T10:30:12') }.to_not raise_error
|
72
|
-
expect { ISO8601::TimeInterval.parse('2014-121T10:11:12Z/2010-05-09T10:30:12Z') }.to_not raise_error
|
73
|
-
expect { ISO8601::TimeInterval.parse('20100509T103012+0400/2010-05-09T10:30:12+04') }.to_not raise_error
|
74
|
-
expect { ISO8601::TimeInterval.parse('20100509/2010-05-09T10:30:12+04:00') }.to_not raise_error
|
75
|
-
expect { ISO8601::TimeInterval.parse('T103012+0400/2010-05-09T10:30:12-04:00') }.to_not raise_error
|
76
|
-
expect { ISO8601::TimeInterval.parse('T103012+04/2010-05-09T10:30:12-00:00') }.to_not raise_error
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'initialization with a ISO8601::Duration' do
|
82
|
-
# it "should raise a ISO8601::Errors::TypeError if parameter is not a ISO8601::Duration" do
|
83
|
-
# datetime = ISO8601::DateTime.new('2010-05-09T10:30:12Z')
|
84
|
-
|
85
|
-
# expect { ISO8601::TimeInterval.from_duration('hi', {}) }.to raise_error(ISO8601::Errors::TypeError)
|
86
|
-
# expect { ISO8601::TimeInterval.from_duration([], {}) }.to raise_error(ISO8601::Errors::TypeError)
|
87
|
-
# expect { ISO8601::TimeInterval.from_duration(datetime, {}) }.to raise_error(ISO8601::Errors::TypeError)
|
88
|
-
# expect { ISO8601::TimeInterval.from_duration({}, {}) }.to raise_error(ISO8601::Errors::TypeError)
|
89
|
-
# end
|
90
|
-
|
91
|
-
# it "should raise an ISO8601::Errors::TypeError if the time hash is no valid" do
|
92
|
-
# duration = ISO8601::Duration.new('P1Y1M1DT0.5H')
|
93
|
-
# datetime = ISO8601::DateTime.new('2010-05-09T10:30:12Z')
|
94
|
-
|
95
|
-
# expect { ISO8601::TimeInterval.from_duration(duration, { time: datetime }) }.to raise_error(ISO8601::Errors::TypeError)
|
96
|
-
# expect { ISO8601::TimeInterval.from_duration(duration, { start_time: nil }) }.to raise_error(ISO8601::Errors::TypeError)
|
97
|
-
# expect { ISO8601::TimeInterval.from_duration(duration, { start_time: datetime, end_time: datetime }) }.to raise_error(ISO8601::Errors::TypeError)
|
98
|
-
# expect { ISO8601::TimeInterval.from_duration(duration, {}) }.to raise_error(ISO8601::Errors::TypeError)
|
99
|
-
# end
|
100
|
-
|
101
|
-
it "should initialize with a valid duration and time" do
|
102
|
-
time = ISO8601::DateTime.new('2010-05-09T10:30:12Z')
|
103
|
-
duration = ISO8601::Duration.new('P1M')
|
104
|
-
|
105
|
-
expect { ISO8601::TimeInterval.from_duration(time, duration) }.to_not raise_error
|
106
|
-
expect { ISO8601::TimeInterval.from_duration(duration, time) }.to_not raise_error
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe 'initialization with a ISO8601::DateTime' do
|
111
|
-
it "should raise a ISO8601::Errors::TypeError if parameters are not an ISO8601::DateTime instance" do
|
112
|
-
duration = ISO8601::Duration.new('P1Y1M1DT0.5H')
|
113
|
-
datetime = ISO8601::DateTime.new('2010-05-09T10:30:12Z')
|
114
|
-
|
115
|
-
expect { ISO8601::TimeInterval.from_datetimes(duration, datetime) }.to raise_error(ISO8601::Errors::TypeError)
|
116
|
-
expect { ISO8601::TimeInterval.from_datetimes(datetime, duration) }.to raise_error(ISO8601::Errors::TypeError)
|
117
|
-
expect { ISO8601::TimeInterval.from_datetimes(datetime, 'Hello!') }.to raise_error(ISO8601::Errors::TypeError)
|
118
|
-
expect { ISO8601::TimeInterval.from_datetimes({}, datetime) }.to raise_error(ISO8601::Errors::TypeError)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should initialize class with a valid datetimes" do
|
122
|
-
datetime = ISO8601::DateTime.new('2010-05-09T10:30:12Z')
|
123
|
-
datetime2 = ISO8601::DateTime.new('2010-05-15T10:30:12Z')
|
124
|
-
|
125
|
-
expect { ISO8601::TimeInterval.from_datetimes(datetime, datetime2) }.to_not raise_error
|
126
|
-
expect { ISO8601::TimeInterval.from_datetimes(datetime2, datetime) }.to_not raise_error
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#to_f" do
|
131
|
-
it "should calculate the size of time interval" do
|
132
|
-
hour = (60 * 60).to_f
|
133
|
-
pattern = 'PT1H/2010-05-09T10:30:00Z'
|
134
|
-
pattern2 = '2010-05-09T11:30:00Z/PT1H'
|
135
|
-
pattern3 = '2010-05-09T11:30:00Z/2010-05-09T12:30:00Z'
|
136
|
-
|
137
|
-
expect(ISO8601::TimeInterval.parse(pattern).to_f).to eq(hour)
|
138
|
-
expect(ISO8601::TimeInterval.parse(pattern2).to_f).to eq(hour)
|
139
|
-
expect(ISO8601::TimeInterval.parse(pattern3).to_f).to eq(hour)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should be 0" do
|
143
|
-
expect(ISO8601::TimeInterval.parse('2015-01-01/2015-01-01').to_f).to eq(0)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "#empty?" do
|
148
|
-
it "should check if the interval is empty" do
|
149
|
-
expect(ISO8601::TimeInterval.parse('2015-01-01/2015-01-01').empty?).to be_truthy
|
150
|
-
expect(ISO8601::TimeInterval.parse('2015-01-01/2015-01-02').empty?).to be_falsy
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe "#start_time" do
|
155
|
-
it "should return always a ISO8601::DateTime object" do
|
156
|
-
pattern = 'PT1H/2010-05-09T10:30:00Z'
|
157
|
-
pattern2 = '2010-05-09T11:30:00Z/PT1H'
|
158
|
-
pattern3 = '2010-05-09T11:30:00Z/2010-05-09T12:30:00Z'
|
159
|
-
|
160
|
-
expect(ISO8601::TimeInterval.parse(pattern).first).to be_an_instance_of(ISO8601::DateTime)
|
161
|
-
expect(ISO8601::TimeInterval.parse(pattern2).first).to be_an_instance_of(ISO8601::DateTime)
|
162
|
-
expect(ISO8601::TimeInterval.parse(pattern3).first).to be_an_instance_of(ISO8601::DateTime)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should calculate correctly the start_time" do
|
166
|
-
start_time = ISO8601::DateTime.new('2010-05-09T10:30:00Z')
|
167
|
-
pattern = 'PT1H/2010-05-09T11:30:00Z'
|
168
|
-
pattern2 = '2010-05-09T10:30:00Z/PT1H'
|
169
|
-
pattern3 = '2010-05-09T10:30:00Z/2010-05-09T12:30:00Z'
|
170
|
-
|
171
|
-
expect(ISO8601::TimeInterval.parse(pattern).first).to eq(start_time)
|
172
|
-
expect(ISO8601::TimeInterval.parse(pattern2).first).to eq(start_time)
|
173
|
-
expect(ISO8601::TimeInterval.parse(pattern3).first).to eq(start_time)
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "November" do
|
177
|
-
pairs = [
|
178
|
-
{pattern: 'P1Y/2017-11-09T07:00:00Z',
|
179
|
-
start_time: ISO8601::DateTime.new('2016-11-09T07:00:00Z')},
|
180
|
-
{pattern: 'P1M/2017-11-09T07:00:00Z',
|
181
|
-
start_time: ISO8601::DateTime.new('2017-10-09T07:00:00Z')},
|
182
|
-
{pattern: 'P1D/2017-11-09T07:00:00Z',
|
183
|
-
start_time: ISO8601::DateTime.new('2017-11-08T07:00:00Z')},
|
184
|
-
{pattern: 'PT1H/2017-11-09T07:00:00Z',
|
185
|
-
start_time: ISO8601::DateTime.new('2017-11-09T06:00:00Z')},
|
186
|
-
]
|
187
|
-
|
188
|
-
pairs.each do |pair|
|
189
|
-
it "should calculate correctly the start_time for #{pair[:pattern]}" do
|
190
|
-
expect(ISO8601::TimeInterval.parse(pair[:pattern]).first.to_s).to eq(pair[:start_time].to_s)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe "December" do
|
196
|
-
pairs = [
|
197
|
-
{pattern: 'P1Y/2017-12-09T07:00:00Z',
|
198
|
-
start_time: ISO8601::DateTime.new('2016-12-09T07:00:00Z')},
|
199
|
-
{pattern: 'P1M/2017-12-09T07:00:00Z',
|
200
|
-
start_time: ISO8601::DateTime.new('2017-11-09T07:00:00Z')},
|
201
|
-
{pattern: 'P3D/2017-12-06T18:30:00Z',
|
202
|
-
start_time: ISO8601::DateTime.new('2017-12-03T18:30:00Z')},
|
203
|
-
{pattern: 'P1D/2017-12-09T07:00:00Z',
|
204
|
-
start_time: ISO8601::DateTime.new('2017-12-08T07:00:00Z')},
|
205
|
-
{pattern: 'PT1H/2017-12-09T07:00:00Z',
|
206
|
-
start_time: ISO8601::DateTime.new('2017-12-09T06:00:00Z')},
|
207
|
-
]
|
208
|
-
|
209
|
-
pairs.each do |pair|
|
210
|
-
it "should calculate correctly the start_time for #{pair[:pattern]}" do
|
211
|
-
expect(ISO8601::TimeInterval.parse(pair[:pattern]).first.to_s).to eq(pair[:start_time].to_s)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "January" do
|
217
|
-
pairs = [
|
218
|
-
{pattern: 'P1Y/2017-01-01T00:00:00Z',
|
219
|
-
start_time: ISO8601::DateTime.new('2016-01-01T00:00:00Z')},
|
220
|
-
{pattern: 'P1M/2017-01-01T00:00:00Z',
|
221
|
-
start_time: ISO8601::DateTime.new('2016-12-01T00:00:00Z')},
|
222
|
-
{pattern: 'P1D/2017-01-01T00:00:00Z',
|
223
|
-
start_time: ISO8601::DateTime.new('2016-12-31T00:00:00Z')},
|
224
|
-
{pattern: 'PT1H/2017-01-01T01:00:00Z',
|
225
|
-
start_time: ISO8601::DateTime.new('2017-01-01T00:00:00Z')},
|
226
|
-
]
|
227
|
-
|
228
|
-
pairs.each do |pair|
|
229
|
-
it "should calculate correctly the start_time for #{pair[:pattern]}" do
|
230
|
-
expect(ISO8601::TimeInterval.parse(pair[:pattern]).first.to_s).to eq(pair[:start_time].to_s)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "February" do
|
236
|
-
pairs = [
|
237
|
-
{pattern: 'P1Y/2017-02-01T00:00:00Z',
|
238
|
-
start_time: ISO8601::DateTime.new('2016-02-01T00:00:00Z')},
|
239
|
-
{pattern: 'P1M/2017-02-01T00:00:00Z',
|
240
|
-
start_time: ISO8601::DateTime.new('2017-01-01T00:00:00Z')},
|
241
|
-
{pattern: 'P1D/2017-02-01T00:00:00Z',
|
242
|
-
start_time: ISO8601::DateTime.new('2017-01-31T00:00:00Z')},
|
243
|
-
{pattern: 'PT1H/2017-02-01T01:00:00Z',
|
244
|
-
start_time: ISO8601::DateTime.new('2017-02-01T00:00:00Z')},
|
245
|
-
]
|
246
|
-
|
247
|
-
pairs.each do |pair|
|
248
|
-
it "should calculate correctly the start_time for #{pair[:pattern]}" do
|
249
|
-
expect(ISO8601::TimeInterval.parse(pair[:pattern]).first.to_s).to eq(pair[:start_time].to_s)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe "March" do
|
255
|
-
pairs = [
|
256
|
-
{pattern: 'P1Y/2017-03-01T00:00:00Z',
|
257
|
-
start_time: ISO8601::DateTime.new('2016-03-01T00:00:00Z')},
|
258
|
-
{pattern: 'P1M/2017-03-01T00:00:00Z',
|
259
|
-
start_time: ISO8601::DateTime.new('2017-02-01T00:00:00Z')},
|
260
|
-
{pattern: 'P1D/2017-03-01T00:00:00Z',
|
261
|
-
start_time: ISO8601::DateTime.new('2017-02-28T00:00:00Z')},
|
262
|
-
{pattern: 'PT1H/2017-03-01T01:00:00Z',
|
263
|
-
start_time: ISO8601::DateTime.new('2017-03-01T00:00:00Z')},
|
264
|
-
]
|
265
|
-
|
266
|
-
pairs.each do |pair|
|
267
|
-
it "should calculate correctly the start_time for #{pair[:pattern]}" do
|
268
|
-
expect(ISO8601::TimeInterval.parse(pair[:pattern]).first.to_s).to eq(pair[:start_time].to_s)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
end
|
277
|
-
|
278
|
-
describe "#last" do
|
279
|
-
it "should return always a ISO8601::DateTime object" do
|
280
|
-
pattern = 'PT1H/2010-05-09T10:30:00Z'
|
281
|
-
pattern2 = '2010-05-09T11:30:00Z/PT1H'
|
282
|
-
pattern3 = '2010-05-09T11:30:00Z/2010-05-09T12:30:00Z'
|
283
|
-
|
284
|
-
expect(ISO8601::TimeInterval.parse(pattern).last).to be_an_instance_of(ISO8601::DateTime)
|
285
|
-
expect(ISO8601::TimeInterval.parse(pattern2).last).to be_an_instance_of(ISO8601::DateTime)
|
286
|
-
expect(ISO8601::TimeInterval.parse(pattern3).last).to be_an_instance_of(ISO8601::DateTime)
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should calculate correctly the last datetime" do
|
290
|
-
end_time = ISO8601::DateTime.new('2010-05-09T10:30:00Z')
|
291
|
-
pattern = 'PT1H/2010-05-09T10:30:00Z'
|
292
|
-
pattern2 = '2010-05-09T09:30:00Z/PT1H'
|
293
|
-
pattern3 = '2010-05-09T09:30:00Z/2010-05-09T10:30:00Z'
|
294
|
-
|
295
|
-
expect(ISO8601::TimeInterval.parse(pattern).last).to eq(end_time)
|
296
|
-
expect(ISO8601::TimeInterval.parse(pattern2).last).to eq(end_time)
|
297
|
-
expect(ISO8601::TimeInterval.parse(pattern3).last).to eq(end_time)
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
describe "#to_s" do
|
302
|
-
it "should return the pattern if TimeInterval is initialized with a pattern" do
|
303
|
-
pattern = 'P1Y1M1DT0,5S/2014-05-31T16:26:10Z'
|
304
|
-
pattern2 = '2007-03-01T13:00:00Z/P1Y'
|
305
|
-
|
306
|
-
expect(ISO8601::TimeInterval.parse(pattern).to_s).to eq(pattern)
|
307
|
-
expect(ISO8601::TimeInterval.parse(pattern2).to_s).to eq(pattern2)
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should build the pattern and return if TimeInterval is initialized with objects" do
|
311
|
-
duration = ISO8601::Duration.new('P1Y1M1DT0.5H')
|
312
|
-
datetime = ISO8601::DateTime.new('2010-05-09T10:30:12+00:00')
|
313
|
-
datetime2 = ISO8601::DateTime.new('2010-05-15T10:30:12+00:00')
|
314
|
-
|
315
|
-
expect(ISO8601::TimeInterval.from_duration(duration, datetime).to_s).to eq('P1Y1M1DT0.5H/2010-05-09T10:30:12+00:00')
|
316
|
-
expect(ISO8601::TimeInterval.from_duration(datetime, duration).to_s).to eq('2010-05-09T10:30:12+00:00/P1Y1M1DT0.5H')
|
317
|
-
expect(ISO8601::TimeInterval.from_datetimes(datetime, datetime2).to_s).to eq('2010-05-09T10:30:12+00:00/2010-05-15T10:30:12+00:00')
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
describe "compare Time Intervals" do
|
322
|
-
before(:each) do
|
323
|
-
@small = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
324
|
-
@big = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT2H')
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should raise TypeError when compared object is not a ISO8601::TimeInterval" do
|
328
|
-
expect { @small < 'Hello!' }.to raise_error(ArgumentError)
|
329
|
-
expect { @small > 'Hello!' }.to raise_error(ArgumentError)
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should check what interval is bigger" do
|
333
|
-
expect(@small <=> @big).to eq(-1)
|
334
|
-
expect(@big <=> @small).to eq(1)
|
335
|
-
expect(@big <=> @big).to eq(0)
|
336
|
-
|
337
|
-
expect(@small > @big).to be_falsy
|
338
|
-
expect(@big > @small).to be_truthy
|
339
|
-
expect(@small > @small).to be_falsy
|
340
|
-
end
|
341
|
-
|
342
|
-
it "should check if interval is bigger or equal than other" do
|
343
|
-
expect(@small >= @big).to be_falsy
|
344
|
-
expect(@big >= @small).to be_truthy
|
345
|
-
expect(@small >= @small).to be_truthy
|
346
|
-
end
|
347
|
-
|
348
|
-
it "should check what interval is smaller" do
|
349
|
-
expect(@small < @big).to be_truthy
|
350
|
-
expect(@big < @small).to be_falsy
|
351
|
-
expect(@small < @small).to be_falsy
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should check if interval is smaller or equal than other" do
|
355
|
-
expect(@small <= @big).to be_truthy
|
356
|
-
expect(@big <= @small).to be_falsy
|
357
|
-
expect(@small <= @small).to be_truthy
|
358
|
-
end
|
359
|
-
|
360
|
-
it "should check if the intervals are equals" do
|
361
|
-
expect(@small == @small).to be_truthy
|
362
|
-
expect(@small == @small.to_f).to be_falsy
|
363
|
-
expect(@small == @big).to be_falsy
|
364
|
-
expect(@small == @big.to_f).to be_falsy
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "#eql?" do
|
369
|
-
it "should be equal only when start_time and end_time are the same" do
|
370
|
-
interval = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
371
|
-
interval2 = ISO8601::TimeInterval.parse('2007-03-01T14:00:00Z/PT1H')
|
372
|
-
interval3 = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
373
|
-
|
374
|
-
expect(interval.eql?(interval2)).to be_falsy
|
375
|
-
expect(interval.eql?(interval3)).to be_truthy
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
describe "#include?" do
|
380
|
-
it "raise TypeError when the parameter is not valid" do
|
381
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
382
|
-
expect { ti.include?('hola') }.to raise_error(ISO8601::Errors::TypeError)
|
383
|
-
expect { ti.include?(123) }.to raise_error(ISO8601::Errors::TypeError)
|
384
|
-
expect { ti.include?(ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')) }.to raise_error(ISO8601::Errors::TypeError)
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should check if a DateTime is included" do
|
388
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1DT1H')
|
389
|
-
included = DateTime.new(2007, 3, 1, 15, 0, 0)
|
390
|
-
included_iso8601 = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
391
|
-
not_included = DateTime.new(2007, 2, 1, 15, 0, 0)
|
392
|
-
not_included_iso8601 = ISO8601::DateTime.new('2007-03-01T11:00:00Z')
|
393
|
-
|
394
|
-
expect(ti.include?(included)).to be_truthy
|
395
|
-
expect(ti.include?(included_iso8601)).to be_truthy
|
396
|
-
expect(ti.include?(not_included)).to be_falsy
|
397
|
-
expect(ti.include?(not_included_iso8601)).to be_falsy
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
describe "#subset?" do
|
402
|
-
it "raise TypeError when the parameter is not valid" do
|
403
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
404
|
-
dt = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
405
|
-
|
406
|
-
expect { ti.subset?('2007-03-01T18:00:00Z') }.to raise_error(ISO8601::Errors::TypeError)
|
407
|
-
expect { ti.subset?(123) }.to raise_error(ISO8601::Errors::TypeError)
|
408
|
-
expect { ti.subset?(dt) }.to raise_error(ISO8601::Errors::TypeError)
|
409
|
-
end
|
410
|
-
|
411
|
-
it "should check if an interval is subset of another one" do
|
412
|
-
ti = ISO8601::TimeInterval.parse('2015-01-15T00:00:00Z/P1D')
|
413
|
-
ti2 = ISO8601::TimeInterval.parse('2015-01-01T00:00:00Z/P1M')
|
414
|
-
|
415
|
-
expect(ti.subset?(ti)).to be_truthy
|
416
|
-
expect(ti.subset?(ti2)).to be_truthy
|
417
|
-
expect(ti2.subset?(ti)).to be_falsy
|
418
|
-
end
|
419
|
-
end
|
420
|
-
|
421
|
-
describe "#superset?" do
|
422
|
-
it "raise TypeError when the parameter is not valid" do
|
423
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
424
|
-
dt = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
425
|
-
|
426
|
-
expect { ti.superset?('2007-03-01T18:00:00Z') }.to raise_error(ISO8601::Errors::TypeError)
|
427
|
-
expect { ti.superset?(123) }.to raise_error(ISO8601::Errors::TypeError)
|
428
|
-
expect { ti.superset?(dt) }.to raise_error(ISO8601::Errors::TypeError)
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should check if the interval is superset of the given one" do
|
432
|
-
ti = ISO8601::TimeInterval.parse('2015-01-01T00:00:00Z/P1M')
|
433
|
-
ti2 = ISO8601::TimeInterval.parse('2015-01-15T00:00:00Z/P1D')
|
434
|
-
ti3 = ISO8601::TimeInterval.parse('2015-03-01T00:00:00Z/P1D')
|
435
|
-
|
436
|
-
expect(ti.superset?(ti)).to be_truthy
|
437
|
-
expect(ti.superset?(ti2)).to be_truthy
|
438
|
-
expect(ti.superset?(ti3)).to be_falsy
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe "#intersect?" do
|
443
|
-
it "raise TypeError when the parameter is not valid" do
|
444
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
445
|
-
dt = DateTime.new(2007, 2, 1, 15, 0, 0)
|
446
|
-
dt_iso8601 = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
447
|
-
|
448
|
-
expect { ti.intersect?('hola') }.to raise_error(ISO8601::Errors::TypeError)
|
449
|
-
expect { ti.intersect?(123) }.to raise_error(ISO8601::Errors::TypeError)
|
450
|
-
expect { ti.intersect?(dt) }.to raise_error(ISO8601::Errors::TypeError)
|
451
|
-
expect { ti.intersect?(dt_iso8601) }.to raise_error(ISO8601::Errors::TypeError)
|
452
|
-
end
|
453
|
-
|
454
|
-
it "should check if two intervals intersect" do
|
455
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1DT1H')
|
456
|
-
included = ISO8601::TimeInterval.parse('2007-03-01T14:00:00Z/PT2H')
|
457
|
-
overlaped = ISO8601::TimeInterval.parse('2007-03-01T18:00:00Z/P1DT1H')
|
458
|
-
not_overlaped = ISO8601::TimeInterval.parse('2007-03-14T14:00:00Z/PT2H')
|
459
|
-
|
460
|
-
expect(ti.intersect?(included)).to be_truthy
|
461
|
-
expect(ti.intersect?(overlaped)).to be_truthy
|
462
|
-
expect(ti.intersect?(not_overlaped)).to be_falsy
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
describe "#intersection" do
|
467
|
-
let(:small) { ISO8601::TimeInterval.parse('2015-06-15/P1D') }
|
468
|
-
let(:big) { ISO8601::TimeInterval.parse('2015-06-01/P1M') }
|
469
|
-
let(:other) { ISO8601::TimeInterval.parse('2015-06-30/P1D') }
|
470
|
-
|
471
|
-
it "raise TypeError when the parameter is not valid" do
|
472
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
473
|
-
dt = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
474
|
-
|
475
|
-
expect { ti.intersection('2007-03-01T13:00:00Z/PT1H') }.to raise_error(ISO8601::Errors::TypeError)
|
476
|
-
expect { ti.intersection(1) }.to raise_error(ISO8601::Errors::TypeError)
|
477
|
-
expect { ti.intersection(dt) }.to raise_error(ISO8601::Errors::TypeError)
|
478
|
-
end
|
479
|
-
|
480
|
-
it "raise IntervalError when the intervals are disjoint" do
|
481
|
-
expect { small.intersection(other) }.to raise_error(ISO8601::Errors::IntervalError)
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should return the smallest when one is subset of the other" do
|
485
|
-
expect(small.intersection(small)).to eq(small)
|
486
|
-
expect(big.intersection(small)).to eq(small)
|
487
|
-
expect(small.intersection(big)).to eq(small)
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
describe "#disjoint?" do
|
492
|
-
it "raise TypeError when the parameter is not valid" do
|
493
|
-
ti = ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/PT1H')
|
494
|
-
dt = ISO8601::DateTime.new('2007-03-01T18:00:00Z')
|
495
|
-
|
496
|
-
expect { ti.disjoint?('2007-03-01T13:00:00Z/PT1H') }.to raise_error(ISO8601::Errors::TypeError)
|
497
|
-
expect { ti.disjoint?(1) }.to raise_error(ISO8601::Errors::TypeError)
|
498
|
-
expect { ti.disjoint?(dt) }.to raise_error(ISO8601::Errors::TypeError)
|
499
|
-
end
|
500
|
-
|
501
|
-
it "should check if two intervals are disjoint" do
|
502
|
-
ti = ISO8601::TimeInterval.parse('2015-01-01T00:00:00Z/P1D')
|
503
|
-
ti2 = ISO8601::TimeInterval.parse('2015-02-01T00:00:00Z/P1D')
|
504
|
-
|
505
|
-
expect(ti.disjoint?(ti)).to be_falsy
|
506
|
-
expect(ti.disjoint?(ti2)).to be_truthy
|
507
|
-
end
|
508
|
-
end
|
509
|
-
end
|