iso8601 0.8.7 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/CONTRIBUTING.md +58 -0
  4. data/Gemfile +2 -2
  5. data/README.md +28 -102
  6. data/docs/date-time.md +86 -0
  7. data/docs/duration.md +77 -0
  8. data/docs/time-interval.md +120 -0
  9. data/iso8601.gemspec +43 -6
  10. data/lib/iso8601.rb +15 -7
  11. data/lib/iso8601/atomic.rb +78 -0
  12. data/lib/iso8601/date.rb +35 -10
  13. data/lib/iso8601/date_time.rb +14 -3
  14. data/lib/iso8601/days.rb +47 -0
  15. data/lib/iso8601/duration.rb +115 -99
  16. data/lib/iso8601/errors.rb +13 -1
  17. data/lib/iso8601/hours.rb +43 -0
  18. data/lib/iso8601/minutes.rb +43 -0
  19. data/lib/iso8601/months.rb +98 -0
  20. data/lib/iso8601/seconds.rb +47 -0
  21. data/lib/iso8601/time.rb +43 -15
  22. data/lib/iso8601/time_interval.rb +392 -0
  23. data/lib/iso8601/version.rb +1 -1
  24. data/lib/iso8601/weeks.rb +43 -0
  25. data/lib/iso8601/years.rb +80 -0
  26. data/spec/iso8601/date_spec.rb +0 -6
  27. data/spec/iso8601/date_time_spec.rb +0 -8
  28. data/spec/iso8601/days_spec.rb +44 -0
  29. data/spec/iso8601/duration_spec.rb +103 -99
  30. data/spec/iso8601/hours_spec.rb +44 -0
  31. data/spec/iso8601/minutes_spec.rb +44 -0
  32. data/spec/iso8601/months_spec.rb +86 -0
  33. data/spec/iso8601/seconds_spec.rb +44 -0
  34. data/spec/iso8601/time_interval_spec.rb +416 -0
  35. data/spec/iso8601/time_spec.rb +0 -6
  36. data/spec/iso8601/weeks_spec.rb +46 -0
  37. data/spec/iso8601/years_spec.rb +69 -0
  38. metadata +37 -19
  39. data/.dockerignore +0 -7
  40. data/.editorconfig +0 -9
  41. data/.gitignore +0 -19
  42. data/.rubocop.yml +0 -38
  43. data/.travis.yml +0 -19
  44. data/Dockerfile +0 -10
  45. data/Makefile +0 -19
  46. data/circle.yml +0 -13
  47. data/lib/iso8601/atoms.rb +0 -279
  48. data/spec/iso8601/atoms_spec.rb +0 -329
@@ -1,329 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe ISO8601::Atom do
4
- it "should raise a TypeError when receives anything but a Numeric value" do
5
- expect { ISO8601::Atom.new('1') }.to raise_error
6
- expect { ISO8601::Atom.new(true) }.to raise_error
7
- expect { ISO8601::Atom.new(-1.1) }.to_not raise_error
8
- expect { ISO8601::Atom.new(-1) }.to_not raise_error
9
- expect { ISO8601::Atom.new(0) }.to_not raise_error
10
- expect { ISO8601::Atom.new(1) }.to_not raise_error
11
- expect { ISO8601::Atom.new(1.1) }.to_not raise_error
12
- end
13
- it "should raise a TypeError when receives anything but a ISO8601::DateTime instance or nil" do
14
- expect { ISO8601::Atom.new(1, ISO8601::DateTime.new('2012-07-07')) }.to_not raise_error
15
- expect { ISO8601::Atom.new(1, nil) }.to_not raise_error
16
- expect { ISO8601::Atom.new(1, true) }.to raise_error
17
- expect { ISO8601::Atom.new(1, 'foo') }.to raise_error
18
- expect { ISO8601::Atom.new(1, 10) }.to raise_error
19
- end
20
- it "should create a new atom" do
21
- expect(ISO8601::Atom.new(-1)).to be_an_instance_of(ISO8601::Atom)
22
- end
23
- describe '#to_i' do
24
- it "should return an integer" do
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)
27
- end
28
- it "should return the integer part of the given number" do
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)
43
- end
44
- end
45
- describe '#factor' do
46
- it "should raise a NotImplementedError" do
47
- expect { ISO8601::Atom.new(1).factor }.to raise_error(NotImplementedError)
48
- end
49
- end
50
- describe '#<=>' do
51
- it "should be comparable to atoms of the same type" do
52
- expect(ISO8601::Atom.new(1) <=> ISO8601::Atom.new(1)).to eq(0)
53
- expect(ISO8601::Atom.new(1) <=> ISO8601::Atom.new(2)).to eq(-1)
54
- expect(ISO8601::Atom.new(2) <=> ISO8601::Atom.new(1)).to eq(1)
55
- expect(ISO8601::Years.new(2) > ISO8601::Years.new(1)).to be_truthy
56
- end
57
- it "should not be comparable to different types" do
58
- expect(ISO8601::Years.new(1) <=> ISO8601::Months.new(1)).to be_nil
59
- expect { ISO8601::Years.new(1) <= 1 }.to raise_error(ArgumentError)
60
- expect { ISO8601::Years.new(2) > 1 }.to raise_error(ArgumentError)
61
- end
62
- it "should be ordered" do
63
- expect(ISO8601::Atom.new(5) > ISO8601::Atom.new(4)).to be_truthy
64
- expect(ISO8601::Atom.new(5) < ISO8601::Atom.new(4)).to be_falsy
65
- end
66
- end
67
- end
68
-
69
- describe ISO8601::Years do
70
- describe '#factor' do
71
- it "should return the Year factor" do
72
- expect { ISO8601::Years.new(1).factor }.to_not raise_error
73
- expect(ISO8601::Years.new(2).factor).to eq(31536000)
74
- expect(ISO8601::Years.new(1).factor).to eq(31536000)
75
- end
76
- it "should return the Year factor for a common year" do
77
- expect(ISO8601::Years.new(1, ISO8601::DateTime.new("2010-01-01")).factor).to eq(31536000)
78
- end
79
- it "should return the Year factor for a leap year" do
80
- expect(ISO8601::Years.new(1, ISO8601::DateTime.new("2000-01-01")).factor).to eq(31622400)
81
- end
82
- end
83
-
84
- describe '#to_seconds' do
85
- it "should return the amount of seconds" do
86
- expect(ISO8601::Years.new(2).to_seconds).to eq(63072000)
87
- expect(ISO8601::Years.new(-2).to_seconds).to eq(-63072000)
88
- end
89
- it "should return the amount of seconds for a common year" do
90
- base = ISO8601::DateTime.new('2010-01-01')
91
- expect(ISO8601::Years.new(2, base).to_seconds).to eq(63072000)
92
- expect(ISO8601::Years.new(12, base).to_seconds).to eq(378691200)
93
- end
94
- it "should return the amount of seconds for a leap year" do
95
- base = ISO8601::DateTime.new('2000-01-01')
96
- expect(ISO8601::Years.new(2, base).to_seconds).to eq(63158400)
97
- expect(ISO8601::Years.new(15, base).to_seconds).to eq(473385600)
98
- end
99
- end
100
-
101
- describe '#symbol' do
102
- it "should return the ISO symbol" do
103
- expect(ISO8601::Years.new(1)).to respond_to(:symbol)
104
- expect(ISO8601::Years.new(1).symbol).to eq(:Y)
105
- end
106
- end
107
-
108
- describe '#hash' do
109
- let(:subject) { ISO8601::Years.new(3) }
110
- it "should respond to #hash" do
111
- expect(subject).to respond_to(:hash)
112
- end
113
- it "should build hash identity by value" do
114
- contrast = ISO8601::Years.new(3)
115
-
116
- expect(subject.hash == contrast.hash).to be_truthy
117
- end
118
- end
119
- end
120
-
121
- describe ISO8601::Months do
122
- describe '#factor' do
123
- it "should return the Month factor" do
124
- expect { ISO8601::Months.new(1).factor }.to_not raise_error
125
- expect(ISO8601::Months.new(2).factor).to eq(2628000)
126
- end
127
- it "should return the Month factor for a common year" do
128
- expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2010-01-01')).factor).to eq(2678400)
129
- end
130
- it "should return the Month factor for a leap year" do
131
- expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2000-01-01')).factor).to eq(2678400)
132
- end
133
- it "should return the Month factor based on february for a common year" do
134
- expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2010-02-01')).factor).to eq(2419200)
135
- end
136
- it "should return the Month factor based on february for a leap year" do
137
- expect(ISO8601::Months.new(1, ISO8601::DateTime.new('2000-02-01')).factor).to eq(2505600)
138
- end
139
- end
140
- describe '#to_seconds' do
141
- it "should return the amount of seconds" do
142
- expect(ISO8601::Months.new(2).to_seconds).to eq(5256000)
143
- end
144
- it "should return the amount of seconds for a common year" do
145
- expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2010-01-01')).to_seconds).to eq(5097600)
146
- end
147
- it "should return the amount of seconds for a leap year" do
148
- expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2000-01-01')).to_seconds).to eq(5184000)
149
- end
150
- it "should return the amount of seconds based on februrary for a common year" do
151
- expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2010-02-01')).to_seconds).to eq(5097600)
152
- end
153
- it "should return the amount of seconds based on february for a leap year" do
154
- expect(ISO8601::Months.new(2, ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(5184000)
155
- expect(ISO8601::Months.new(12, ISO8601::DateTime.new('2000-02-01')).to_seconds).to eq(31622400)
156
- 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)
157
- end
158
- end
159
- describe '#symbol' do
160
- it "should return the ISO symbol" do
161
- expect(ISO8601::Months.new(1)).to respond_to(:symbol)
162
- expect(ISO8601::Months.new(1).symbol).to eq(:M)
163
- end
164
- end
165
-
166
- describe '#hash' do
167
- let(:subject) { ISO8601::Months.new(3) }
168
- it "should respond to #hash" do
169
- expect(subject).to respond_to(:hash)
170
- end
171
- it "should build hash identity by value" do
172
- contrast = ISO8601::Months.new(3)
173
-
174
- expect(subject.hash == contrast.hash).to be_truthy
175
- end
176
- end
177
- end
178
-
179
- describe ISO8601::Weeks do
180
- describe '#factor' do
181
- it "should return the Week factor" do
182
- expect(ISO8601::Weeks.new(2).factor).to eq(604800)
183
- end
184
- end
185
- describe '#to_seconds' do
186
- it "should return the amount of seconds" do
187
- expect(ISO8601::Weeks.new(2).to_seconds).to eq(1209600)
188
- expect(ISO8601::Weeks.new(-2).to_seconds).to eq(-1209600)
189
- end
190
- end
191
- describe '#symbol' do
192
- it "should return the ISO symbol" do
193
- expect(ISO8601::Weeks.new(1)).to respond_to(:symbol)
194
- expect(ISO8601::Weeks.new(1).symbol).to eq(:W)
195
- end
196
- end
197
-
198
- describe '#hash' do
199
- let(:subject) { ISO8601::Weeks.new(3) }
200
- it "should respond to #hash" do
201
- expect(subject).to respond_to(:hash)
202
- end
203
- it "should build hash identity by value" do
204
- contrast = ISO8601::Weeks.new(3)
205
-
206
- expect(subject.hash == contrast.hash).to be_truthy
207
- end
208
- end
209
- end
210
-
211
- describe ISO8601::Days do
212
- describe '#factor' do
213
- it "should return the Day factor" do
214
- expect(ISO8601::Days.new(2).factor).to eq(86400)
215
- end
216
- it "should return the amount of seconds" do
217
- expect(ISO8601::Days.new(2).to_seconds).to eq(172800)
218
- expect(ISO8601::Days.new(-2).to_seconds).to eq(-172800)
219
- end
220
- end
221
- describe '#symbol' do
222
- it "should return the ISO symbol" do
223
- expect(ISO8601::Days.new(1)).to respond_to(:symbol)
224
- expect(ISO8601::Days.new(1).symbol).to eq(:D)
225
- end
226
- end
227
-
228
- describe '#hash' do
229
- let(:subject) { ISO8601::Days.new(3) }
230
- it "should respond to #hash" do
231
- expect(subject).to respond_to(:hash)
232
- end
233
- it "should build hash identity by value" do
234
- contrast = ISO8601::Days.new(3)
235
-
236
- expect(subject.hash == contrast.hash).to be_truthy
237
- end
238
- end
239
- end
240
-
241
- describe ISO8601::Hours do
242
- describe '#factor' do
243
- it "should return the Hour factor" do
244
- expect(ISO8601::Hours.new(2).factor).to eq(3600)
245
- end
246
- it "should return the amount of seconds" do
247
- expect(ISO8601::Hours.new(2).to_seconds).to eq(7200)
248
- expect(ISO8601::Hours.new(-2).to_seconds).to eq(-7200)
249
- end
250
- end
251
- describe '#symbol' do
252
- it "should return the ISO symbol" do
253
- expect(ISO8601::Hours.new(1)).to respond_to(:symbol)
254
- expect(ISO8601::Hours.new(1).symbol).to eq(:H)
255
- end
256
- end
257
-
258
- describe '#hash' do
259
- let(:subject) { ISO8601::Hours.new(3) }
260
- it "should respond to #hash" do
261
- expect(subject).to respond_to(:hash)
262
- end
263
- it "should build hash identity by value" do
264
- contrast = ISO8601::Hours.new(3)
265
-
266
- expect(subject.hash == contrast.hash).to be_truthy
267
- end
268
- end
269
- end
270
-
271
- describe ISO8601::Minutes do
272
- describe '#factor' do
273
- it "should return the Minute factor" do
274
- expect(ISO8601::Minutes.new(2).factor).to eq(60)
275
- end
276
- it "should return the amount of seconds" do
277
- expect(ISO8601::Minutes.new(2).to_seconds).to eq(120)
278
- expect(ISO8601::Minutes.new(-2).to_seconds).to eq(-120)
279
- end
280
- end
281
- describe '#symbol' do
282
- it "should return the ISO symbol" do
283
- expect(ISO8601::Minutes.new(1)).to respond_to(:symbol)
284
- expect(ISO8601::Minutes.new(1).symbol).to eq(:M)
285
- end
286
- end
287
-
288
- describe '#hash' do
289
- let(:subject) { ISO8601::Minutes.new(3) }
290
- it "should respond to #hash" do
291
- expect(subject).to respond_to(:hash)
292
- end
293
- it "should build hash identity by value" do
294
- contrast = ISO8601::Minutes.new(3)
295
-
296
- expect(subject.hash == contrast.hash).to be_truthy
297
- end
298
- end
299
- end
300
-
301
- describe ISO8601::Seconds do
302
- describe '#factor' do
303
- it "should return the Second factor" do
304
- expect(ISO8601::Seconds.new(2).factor).to eq(1)
305
- end
306
- it "should return the amount of seconds" do
307
- expect(ISO8601::Seconds.new(2).to_seconds).to eq(2)
308
- expect(ISO8601::Seconds.new(-2).to_seconds).to eq(-2)
309
- end
310
- end
311
- describe '#symbol' do
312
- it "should return the ISO symbol" do
313
- expect(ISO8601::Seconds.new(1)).to respond_to(:symbol)
314
- expect(ISO8601::Seconds.new(1).symbol).to eq(:S)
315
- end
316
- end
317
-
318
- describe '#hash' do
319
- let(:subject) { ISO8601::Seconds.new(3) }
320
- it "should respond to #hash" do
321
- expect(subject).to respond_to(:hash)
322
- end
323
- it "should build hash identity by value" do
324
- contrast = ISO8601::Seconds.new(3)
325
-
326
- expect(subject.hash == contrast.hash).to be_truthy
327
- end
328
- end
329
- end