iso8601 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +1 -2
- data/README.md +1 -3
- data/Rakefile +0 -1
- data/iso8601.gemspec +9 -10
- data/lib/iso8601.rb +0 -2
- data/lib/iso8601/atomic.rb +5 -7
- data/lib/iso8601/date.rb +2 -1
- data/lib/iso8601/date_time.rb +6 -9
- data/lib/iso8601/days.rb +0 -2
- data/lib/iso8601/duration.rb +16 -17
- data/lib/iso8601/hours.rb +0 -2
- data/lib/iso8601/minutes.rb +0 -2
- data/lib/iso8601/months.rb +5 -19
- data/lib/iso8601/seconds.rb +0 -2
- data/lib/iso8601/time.rb +4 -5
- data/lib/iso8601/time_interval.rb +50 -47
- data/lib/iso8601/version.rb +1 -1
- data/lib/iso8601/weeks.rb +0 -2
- data/lib/iso8601/years.rb +5 -5
- data/spec/iso8601/date_time_spec.rb +0 -2
- data/spec/iso8601/duration_spec.rb +3 -13
- data/spec/iso8601/hours_spec.rb +11 -11
- data/spec/iso8601/minutes_spec.rb +11 -11
- data/spec/iso8601/months_spec.rb +19 -11
- data/spec/iso8601/seconds_spec.rb +11 -11
- data/spec/iso8601/time_interval_spec.rb +103 -10
- data/spec/iso8601/weeks_spec.rb +11 -11
- data/spec/iso8601/years_spec.rb +12 -11
- data/spec/spec_helper.rb +0 -2
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c7b4ba1e602e306fa8bc033780f6a4f239aa2d592b4721f78e17dfc20bf61bc
|
4
|
+
data.tar.gz: e7eeec472d8ed97d6ca44790b633c5ce881c26ae7363db7d6f786b7c8032b6e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a2c878595f95c960deb2c70ea2a27adf74930545518147d3d0364ef23874a4efb54c5b6f640ef4df463994eed013afb78b3d7002b7796ef588873f966907cb6
|
7
|
+
data.tar.gz: ea64e2bb8a9bebb77f8ad5d4611db9c72904e815abfd8047843b0dee1c5f4c6b9e95d081c23738f4098c80229774f707c598e61437e698c8f5b93f5d1448c9d1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.10.0
|
2
|
+
|
3
|
+
* Fix `TimeInterval` with `<duration>/<end>` patterns and leap years.
|
4
|
+
* Fix decimal fractions on date atoms. **WARNING** some duration patterns are
|
5
|
+
no longer valid.
|
6
|
+
|
1
7
|
## 0.9.1
|
2
8
|
|
3
9
|
* Fix `Duration#to_pattern` for negative durations based on a `Numeric` (thanks @figwit).
|
data/CONTRIBUTING.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
u ISO8601
|
2
2
|
|
3
3
|
Version 0.9.0 is **not compatible** with previous versions. Atoms and Durations
|
4
4
|
changed their interface when treating base dates so it is only applied when
|
@@ -24,7 +24,6 @@ times) standard.
|
|
24
24
|
## Supported versions
|
25
25
|
|
26
26
|
* MRI 2.x
|
27
|
-
* RBX 2
|
28
27
|
* JRuby 9
|
29
28
|
|
30
29
|
## Documentation
|
@@ -49,7 +48,6 @@ take a look to the implementation notes:
|
|
49
48
|
You can alse target specific runtimes:
|
50
49
|
|
51
50
|
$ make mri-test
|
52
|
-
$ make rbx-test
|
53
51
|
$ make jruby-test
|
54
52
|
|
55
53
|
### Raw
|
data/Rakefile
CHANGED
data/iso8601.gemspec
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
2
|
require 'iso8601/version'
|
5
3
|
|
4
|
+
# rubocop:disable Metrics/BlockLength
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = 'iso8601'
|
8
7
|
s.version = ISO8601::VERSION
|
@@ -11,14 +10,14 @@ Gem::Specification.new do |s|
|
|
11
10
|
s.email = 'arnau.siches@gmail.com'
|
12
11
|
s.homepage = 'https://github.com/arnau/ISO8601'
|
13
12
|
s.summary = "Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601"
|
14
|
-
s.description = <<-
|
13
|
+
s.description = <<-DESC
|
15
14
|
ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and
|
16
15
|
interchange formats - Information interchange - Representation of dates
|
17
16
|
and times) standard.
|
18
|
-
|
17
|
+
DESC
|
19
18
|
s.license = 'MIT'
|
20
19
|
s.rubyforge_project = 'iso8601'
|
21
|
-
s.files = %
|
20
|
+
s.files = %w[CHANGELOG.md
|
22
21
|
CONTRIBUTING.md
|
23
22
|
Gemfile
|
24
23
|
LICENSE
|
@@ -56,14 +55,14 @@ Gem::Specification.new do |s|
|
|
56
55
|
spec/iso8601/time_spec.rb
|
57
56
|
spec/iso8601/weeks_spec.rb
|
58
57
|
spec/iso8601/years_spec.rb
|
59
|
-
spec/spec_helper.rb
|
58
|
+
spec/spec_helper.rb]
|
60
59
|
s.test_files = s.files.grep(%r{^spec/})
|
61
60
|
s.require_paths = ['lib']
|
62
61
|
|
63
62
|
s.has_rdoc = 'yard'
|
64
63
|
s.required_ruby_version = '>= 2.0.0'
|
65
|
-
s.add_development_dependency 'rspec', '~> 3.
|
66
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
67
|
-
s.add_development_dependency 'pry', '~> 0.
|
68
|
-
s.add_development_dependency 'pry-doc', '~> 0.
|
64
|
+
s.add_development_dependency 'rspec', '~> 3.6'
|
65
|
+
s.add_development_dependency 'rubocop', '~> 0.50'
|
66
|
+
s.add_development_dependency 'pry', '~> 0.11.0'
|
67
|
+
s.add_development_dependency 'pry-doc', '~> 0.11.0'
|
69
68
|
end
|
data/lib/iso8601.rb
CHANGED
data/lib/iso8601/atomic.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module ISO8601
|
4
2
|
module Atomic
|
5
3
|
include Comparable
|
@@ -27,7 +25,7 @@ module ISO8601
|
|
27
25
|
#
|
28
26
|
# @return [String]
|
29
27
|
def to_s
|
30
|
-
|
28
|
+
value.zero? ? '' : "#{value}#{symbol}"
|
31
29
|
end
|
32
30
|
|
33
31
|
##
|
@@ -66,13 +64,13 @@ module ISO8601
|
|
66
64
|
##
|
67
65
|
# Validates the atom is a Numeric
|
68
66
|
def valid_atom?(atom)
|
69
|
-
|
70
|
-
|
67
|
+
raise(ISO8601::Errors::TypeError, "The atom argument for #{self.class} should be a Numeric value.") \
|
68
|
+
unless atom.is_a?(Numeric)
|
71
69
|
end
|
72
70
|
|
73
71
|
def valid_base?(base)
|
74
|
-
|
75
|
-
|
72
|
+
raise(ISO8601::Errors::TypeError, "The base argument for #{self.class} should be a ISO8601::DateTime instance or nil.") \
|
73
|
+
unless base.is_a?(ISO8601::DateTime) || base.nil?
|
76
74
|
end
|
77
75
|
end
|
78
76
|
end
|
data/lib/iso8601/date.rb
CHANGED
@@ -112,6 +112,7 @@ module ISO8601
|
|
112
112
|
# @param [String] input
|
113
113
|
#
|
114
114
|
# @return [Array<Integer>]
|
115
|
+
# rubocop:disable Metrics/AbcSize
|
115
116
|
def atomize(input)
|
116
117
|
week_date = parse_weekdate(input)
|
117
118
|
return atomize_week_date(input, week_date[2], week_date[1]) unless week_date.nil?
|
@@ -121,7 +122,7 @@ module ISO8601
|
|
121
122
|
|
122
123
|
_, year, separator, month, day = parse_date(input)
|
123
124
|
|
124
|
-
|
125
|
+
raise(ISO8601::Errors::UnknownPattern, @original) if year.nil?
|
125
126
|
|
126
127
|
@separator = separator
|
127
128
|
|
data/lib/iso8601/date_time.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module ISO8601
|
4
2
|
##
|
5
3
|
# A DateTime representation
|
@@ -59,7 +57,7 @@ module ISO8601
|
|
59
57
|
def to_a
|
60
58
|
[year, month, day, hour, minute, second, zone]
|
61
59
|
end
|
62
|
-
|
60
|
+
alias atoms to_a
|
63
61
|
|
64
62
|
##
|
65
63
|
# Converts DateTime to a floating point number of seconds since the Epoch.
|
@@ -98,8 +96,9 @@ module ISO8601
|
|
98
96
|
# It enhances the parsing capabilities of the native DateTime.
|
99
97
|
#
|
100
98
|
# @param [String] date_time The ISO representation
|
99
|
+
# rubocop:disable Metrics/AbcSize
|
101
100
|
def parse(date_time)
|
102
|
-
|
101
|
+
raise(ISO8601::Errors::UnknownPattern, date_time) if date_time.empty?
|
103
102
|
|
104
103
|
date, time = date_time.split('T')
|
105
104
|
|
@@ -107,10 +106,8 @@ module ISO8601
|
|
107
106
|
time_atoms = Array(time && parse_time(time))
|
108
107
|
separators = [date_atoms.pop, time_atoms.pop]
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
fail ISO8601::Errors::UnknownPattern,
|
113
|
-
@original unless valid_separators?(separators)
|
109
|
+
raise(ISO8601::Errors::UnknownPattern, @original) unless valid_representation?(date_atoms, time_atoms)
|
110
|
+
raise(ISO8601::Errors::UnknownPattern, @original) unless valid_separators?(separators)
|
114
111
|
|
115
112
|
::DateTime.new(*(date_atoms + time_atoms).compact)
|
116
113
|
end
|
@@ -146,7 +143,7 @@ module ISO8601
|
|
146
143
|
return true if separators.length == 1 || separators[0] == :ignore
|
147
144
|
|
148
145
|
unless separators.all?(&:empty?)
|
149
|
-
return false if
|
146
|
+
return false if separators.first.length != separators.last.length
|
150
147
|
end
|
151
148
|
|
152
149
|
true
|
data/lib/iso8601/days.rb
CHANGED
data/lib/iso8601/duration.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module ISO8601
|
4
2
|
##
|
5
3
|
# A duration representation. When no base is provided, all atoms use an
|
@@ -24,6 +22,7 @@ module ISO8601
|
|
24
22
|
# di == dp # => true
|
25
23
|
# di == ds # => true
|
26
24
|
#
|
25
|
+
# rubocop:disable Metrics/ClassLength
|
27
26
|
class Duration
|
28
27
|
##
|
29
28
|
# @param [String, Numeric] input The duration pattern
|
@@ -42,7 +41,7 @@ module ISO8601
|
|
42
41
|
##
|
43
42
|
# @return [String] The string representation of the duration
|
44
43
|
attr_reader :pattern
|
45
|
-
|
44
|
+
alias to_s pattern
|
46
45
|
|
47
46
|
##
|
48
47
|
# @return [ISO8601::Years] The years of the duration
|
@@ -188,7 +187,7 @@ module ISO8601
|
|
188
187
|
#
|
189
188
|
# @return [Hash<Float>]
|
190
189
|
def atomize(input)
|
191
|
-
duration = parse(input) ||
|
190
|
+
duration = parse(input) || raise(ISO8601::Errors::UnknownPattern, input)
|
192
191
|
|
193
192
|
valid_pattern?(duration)
|
194
193
|
|
@@ -212,7 +211,7 @@ module ISO8601
|
|
212
211
|
end
|
213
212
|
|
214
213
|
def sign_to_i(sign)
|
215
|
-
|
214
|
+
sign == '-' ? -1 : 1
|
216
215
|
end
|
217
216
|
|
218
217
|
def parse(input)
|
@@ -220,9 +219,9 @@ module ISO8601
|
|
220
219
|
(?<sign>\+|-)?
|
221
220
|
P(?:
|
222
221
|
(?:
|
223
|
-
(?:(?<years>\d+
|
224
|
-
(?:(?<months>\d+
|
225
|
-
(?:(?<days>\d+
|
222
|
+
(?:(?<years>\d+)Y)?
|
223
|
+
(?:(?<months>\d+)M)?
|
224
|
+
(?:(?<days>\d+)D)?
|
226
225
|
(?<time>T
|
227
226
|
(?:(?<hours>\d+(?:[.,]\d+)?)H)?
|
228
227
|
(?:(?<minutes>\d+(?:[.,]\d+)?)M)?
|
@@ -238,10 +237,11 @@ module ISO8601
|
|
238
237
|
# @param [Numeric] value The seconds to promote
|
239
238
|
#
|
240
239
|
# @return [ISO8601::Duration]
|
240
|
+
# rubocop:disable Metrics/AbcSize
|
241
241
|
def seconds_to_iso(value)
|
242
242
|
return self.class.new('PT0S') if value.zero?
|
243
243
|
|
244
|
-
sign_str =
|
244
|
+
sign_str = value < 0 ? '-' : ''
|
245
245
|
value = value.abs
|
246
246
|
|
247
247
|
y, y_mod = decompose_atom(value, years)
|
@@ -266,11 +266,11 @@ module ISO8601
|
|
266
266
|
end
|
267
267
|
|
268
268
|
def to_time_s(*args)
|
269
|
-
|
269
|
+
args.map(&:value).reduce(&:+) > 0 ? "T#{args.map(&:to_s).join('')}" : ''
|
270
270
|
end
|
271
271
|
|
272
272
|
def validate_base(input)
|
273
|
-
|
273
|
+
raise(ISO8601::Errors::TypeError) unless input.nil? || input.is_a?(ISO8601::DateTime)
|
274
274
|
|
275
275
|
input
|
276
276
|
end
|
@@ -288,20 +288,19 @@ module ISO8601
|
|
288
288
|
missing_time = (weeks.nil? && !components[:time].nil? && time.empty?)
|
289
289
|
empty = missing_time || all.empty?
|
290
290
|
|
291
|
-
|
292
|
-
@pattern if empty
|
291
|
+
raise(ISO8601::Errors::UnknownPattern, @pattern) if empty
|
293
292
|
end
|
294
293
|
|
295
294
|
def valid_fractions?(values)
|
296
295
|
values = values.reject(&:zero?)
|
297
|
-
fractions = values.
|
296
|
+
fractions = values.reject { |a| (a % 1).zero? }
|
298
297
|
consistent = (fractions.size == 1 && fractions.last != values.last)
|
299
298
|
|
300
|
-
|
299
|
+
raise(ISO8601::Errors::InvalidFractions) if fractions.size > 1 || consistent
|
301
300
|
end
|
302
301
|
|
303
302
|
def compare_bases(other, base)
|
304
|
-
|
303
|
+
raise(ISO8601::Errors::DurationBaseError, other) if base != other.base
|
305
304
|
end
|
306
305
|
|
307
306
|
##
|
@@ -321,7 +320,7 @@ module ISO8601
|
|
321
320
|
when Numeric
|
322
321
|
other.to_f
|
323
322
|
else
|
324
|
-
|
323
|
+
raise(ISO8601::Errors::TypeError, other)
|
325
324
|
end
|
326
325
|
end
|
327
326
|
end
|
data/lib/iso8601/hours.rb
CHANGED
data/lib/iso8601/minutes.rb
CHANGED
data/lib/iso8601/months.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module ISO8601
|
4
2
|
##
|
5
3
|
# A Months atom in a {ISO8601::Duration}
|
@@ -36,7 +34,7 @@ module ISO8601
|
|
36
34
|
# @return [Numeric]
|
37
35
|
def factor(base = nil)
|
38
36
|
return AVERAGE_FACTOR if base.nil?
|
39
|
-
return
|
37
|
+
return calculation(1, base) if atom.zero?
|
40
38
|
|
41
39
|
calculation(atom, base)
|
42
40
|
end
|
@@ -49,12 +47,7 @@ module ISO8601
|
|
49
47
|
#
|
50
48
|
# @return [Numeric]
|
51
49
|
def to_seconds(base = nil)
|
52
|
-
|
53
|
-
|
54
|
-
return (AVERAGE_FACTOR * atom) if base.nil?
|
55
|
-
return zero_calculation(base) if atom.zero?
|
56
|
-
|
57
|
-
calculation(atom, base) * atom
|
50
|
+
factor(base) * atom
|
58
51
|
end
|
59
52
|
|
60
53
|
##
|
@@ -67,27 +60,20 @@ module ISO8601
|
|
67
60
|
|
68
61
|
private
|
69
62
|
|
70
|
-
def zero_calculation(base)
|
71
|
-
month = (base.month <= 12) ? base.month : (base.month % 12)
|
72
|
-
year = base.year + ((base.month) / 12).to_i
|
73
|
-
|
74
|
-
(::Time.utc(year, month) - ::Time.utc(base.year, base.month))
|
75
|
-
end
|
76
|
-
|
77
63
|
def calculation(atom, base)
|
78
64
|
initial = base.month + atom
|
79
65
|
if initial <= 0
|
80
66
|
month = base.month + atom
|
81
67
|
|
82
|
-
if initial % 12
|
68
|
+
if (initial % 12).zero?
|
83
69
|
year = base.year + (initial / 12) - 1
|
84
70
|
month = 12
|
85
71
|
else
|
86
72
|
year = base.year + (initial / 12).floor
|
87
|
-
month =
|
73
|
+
month = 12 + initial > 0 ? (12 + initial) : (12 + (initial % -12))
|
88
74
|
end
|
89
75
|
else
|
90
|
-
month =
|
76
|
+
month = initial <= 12 ? initial : (initial % 12)
|
91
77
|
month = 12 if month.zero?
|
92
78
|
year = base.year + ((base.month + atom) / 12).to_i
|
93
79
|
end
|
data/lib/iso8601/seconds.rb
CHANGED
data/lib/iso8601/time.rb
CHANGED
@@ -113,12 +113,12 @@ module ISO8601
|
|
113
113
|
# @param [String] input
|
114
114
|
#
|
115
115
|
# @return [Array<Integer, Float>]
|
116
|
+
# rubocop:disable Metrics/AbcSize
|
116
117
|
def atomize(input)
|
117
118
|
_, time, zone = parse_timezone(input)
|
118
119
|
_, hour, separator, minute, second = parse_time(time)
|
119
120
|
|
120
|
-
|
121
|
-
@original if hour.nil?
|
121
|
+
raise(ISO8601::Errors::UnknownPattern, @original) if hour.nil?
|
122
122
|
|
123
123
|
@separator = separator
|
124
124
|
require_separator = require_separator(minute)
|
@@ -129,8 +129,7 @@ module ISO8601
|
|
129
129
|
|
130
130
|
atoms = [hour, minute, second, zone].compact
|
131
131
|
|
132
|
-
|
133
|
-
@original unless valid_zone?(zone, require_separator)
|
132
|
+
raise(ISO8601::Errors::UnknownPattern, @original) unless valid_zone?(zone, require_separator)
|
134
133
|
|
135
134
|
atoms
|
136
135
|
end
|
@@ -180,7 +179,7 @@ module ISO8601
|
|
180
179
|
#
|
181
180
|
# @return [::DateTime]
|
182
181
|
def compose(atoms, base)
|
183
|
-
::DateTime.new(
|
182
|
+
::DateTime.new(base.year, base.month, base.day, *atoms)
|
184
183
|
rescue ArgumentError
|
185
184
|
raise ISO8601::Errors::RangeError, @original
|
186
185
|
end
|
@@ -95,7 +95,7 @@ module ISO8601
|
|
95
95
|
when Array
|
96
96
|
from_atoms(input)
|
97
97
|
else
|
98
|
-
|
98
|
+
raise(ISO8601::Errors::TypeError, 'The pattern must be a String or a Hash')
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -111,14 +111,14 @@ module ISO8601
|
|
111
111
|
#
|
112
112
|
# @return [ISO8601::DateTime] start time
|
113
113
|
attr_reader :first
|
114
|
-
|
114
|
+
alias start_time first
|
115
115
|
|
116
116
|
##
|
117
117
|
# The end time (last) of the interval.
|
118
118
|
#
|
119
119
|
# @return [ISO8601::DateTime] end time
|
120
120
|
attr_reader :last
|
121
|
-
|
121
|
+
alias end_time last
|
122
122
|
|
123
123
|
##
|
124
124
|
# The pattern for the interval.
|
@@ -129,7 +129,7 @@ module ISO8601
|
|
129
129
|
|
130
130
|
"#{@atoms.first}/#{@atoms.last}"
|
131
131
|
end
|
132
|
-
|
132
|
+
alias to_s pattern
|
133
133
|
|
134
134
|
##
|
135
135
|
# The size of the interval. If any bound is a Duration, the
|
@@ -137,8 +137,8 @@ module ISO8601
|
|
137
137
|
#
|
138
138
|
# @return [Float] Size of the interval in seconds
|
139
139
|
attr_reader :size
|
140
|
-
|
141
|
-
|
140
|
+
alias to_f size
|
141
|
+
alias length size
|
142
142
|
|
143
143
|
##
|
144
144
|
# Checks if the interval is empty.
|
@@ -159,13 +159,13 @@ module ISO8601
|
|
159
159
|
#
|
160
160
|
# @return [Boolean]
|
161
161
|
def include?(other)
|
162
|
-
|
162
|
+
raise(ISO8601::Errors::TypeError, "The parameter must respond_to #to_time") \
|
163
163
|
unless other.respond_to?(:to_time)
|
164
164
|
|
165
165
|
(first.to_time <= other.to_time &&
|
166
166
|
last.to_time >= other.to_time)
|
167
167
|
end
|
168
|
-
|
168
|
+
alias member? include?
|
169
169
|
|
170
170
|
##
|
171
171
|
# Returns true if the interval is a subset of the given interval.
|
@@ -177,7 +177,7 @@ module ISO8601
|
|
177
177
|
#
|
178
178
|
# @return [Boolean]
|
179
179
|
def subset?(other)
|
180
|
-
|
180
|
+
raise(ISO8601::Errors::TypeError, "The parameter must be an instance of #{self.class}") \
|
181
181
|
unless other.is_a?(self.class)
|
182
182
|
|
183
183
|
other.include?(first) && other.include?(last)
|
@@ -193,7 +193,7 @@ module ISO8601
|
|
193
193
|
#
|
194
194
|
# @return [Boolean]
|
195
195
|
def superset?(other)
|
196
|
-
|
196
|
+
raise(ISO8601::Errors::TypeError, "The parameter must be an instance of #{self.class}") \
|
197
197
|
unless other.is_a?(self.class)
|
198
198
|
|
199
199
|
include?(other.first) && include?(other.last)
|
@@ -209,8 +209,7 @@ module ISO8601
|
|
209
209
|
#
|
210
210
|
# @return [Boolean]
|
211
211
|
def intersect?(other)
|
212
|
-
|
213
|
-
"The parameter must be an instance of #{self.class}") \
|
212
|
+
raise(ISO8601::Errors::TypeError, "The parameter must be an instance of #{self.class}") \
|
214
213
|
unless other.is_a?(self.class)
|
215
214
|
|
216
215
|
include?(other.first) || include?(other.last)
|
@@ -225,7 +224,7 @@ module ISO8601
|
|
225
224
|
#
|
226
225
|
# @return [Boolean]
|
227
226
|
def intersection(other)
|
228
|
-
|
227
|
+
raise(ISO8601::Errors::IntervalError, "The intervals are disjoint") \
|
229
228
|
if disjoint?(other) && other.disjoint?(self)
|
230
229
|
|
231
230
|
return self if subset?(other)
|
@@ -274,14 +273,30 @@ module ISO8601
|
|
274
273
|
@atoms.hash
|
275
274
|
end
|
276
275
|
|
276
|
+
def self.valid_date_time?(time, message = "Expected a ISO8601::DateTime")
|
277
|
+
return true if time.is_a?(ISO8601::DateTime)
|
278
|
+
|
279
|
+
raise(ISO8601::Errors::TypeError, message)
|
280
|
+
end
|
281
|
+
|
282
|
+
def self.guard_from_datetimes(atoms, message)
|
283
|
+
atoms.all? { |x| valid_date_time?(x, message) }
|
284
|
+
end
|
285
|
+
|
286
|
+
def self.guard_from_duration(atoms, message)
|
287
|
+
raise(ISO8601::Errors::TypeError, message) \
|
288
|
+
unless atoms.any? { |x| x.is_a?(ISO8601::Duration) } &&
|
289
|
+
atoms.any? { |x| x.is_a?(ISO8601::DateTime) }
|
290
|
+
end
|
291
|
+
|
277
292
|
private
|
278
293
|
|
279
294
|
# Initialize a TimeInterval ISO8601 by a pattern. If you initialize it with
|
280
295
|
# a duration pattern, the second argument is mandatory because you need to
|
281
296
|
# specify an start/end point to calculate the interval.
|
282
297
|
#
|
283
|
-
# @param [String] pattern This parameter
|
284
|
-
# patterns are defined in the ISO8601:
|
298
|
+
# @param [String] pattern This parameter defines a full time interval.
|
299
|
+
# Valid patterns are defined in the ISO8601 as:
|
285
300
|
# * <start_time>/<end_time>
|
286
301
|
# * <start_time>/<duration>
|
287
302
|
# * <duration>/<end_time>
|
@@ -289,19 +304,21 @@ module ISO8601
|
|
289
304
|
# @raise [ISO8601::Errors::UnknownPattern] If given pattern is not a valid
|
290
305
|
# ISO8601 pattern.
|
291
306
|
def parse(pattern)
|
292
|
-
|
307
|
+
raise(ISO8601::Errors::UnknownPattern, pattern) unless pattern.include?('/')
|
293
308
|
|
294
309
|
@pattern = pattern
|
295
310
|
subpatterns = pattern.split('/')
|
296
311
|
|
297
|
-
|
312
|
+
raise(ISO8601::Errors::UnknownPattern, pattern) if subpatterns.size != 2
|
298
313
|
|
299
|
-
|
314
|
+
fst = parse_start_subpattern(subpatterns.first)
|
315
|
+
snd = parse_subpattern(subpatterns.last)
|
316
|
+
@atoms = [fst, snd]
|
300
317
|
@first, @last, @size = limits(@atoms)
|
301
318
|
end
|
302
319
|
|
303
320
|
def sort_pair(a, b)
|
304
|
-
|
321
|
+
a.first < b.first ? [a, b] : [b, a]
|
305
322
|
end
|
306
323
|
|
307
324
|
##
|
@@ -316,6 +333,12 @@ module ISO8601
|
|
316
333
|
ISO8601::DateTime.new(pattern)
|
317
334
|
end
|
318
335
|
|
336
|
+
def parse_start_subpattern(pattern)
|
337
|
+
return ISO8601::Duration.new("-#{pattern}") if pattern.start_with?('P')
|
338
|
+
|
339
|
+
ISO8601::DateTime.new(pattern)
|
340
|
+
end
|
341
|
+
|
319
342
|
##
|
320
343
|
# See the constructor methods.
|
321
344
|
#
|
@@ -334,13 +357,10 @@ module ISO8601
|
|
334
357
|
def limits(atoms)
|
335
358
|
valid_atoms?(atoms)
|
336
359
|
|
337
|
-
if atoms.none? { |x| x.is_a?(ISO8601::Duration) }
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
else
|
342
|
-
return tuple_by_start(atoms)
|
343
|
-
end
|
360
|
+
return tuple_by_both(atoms) if atoms.none? { |x| x.is_a?(ISO8601::Duration) }
|
361
|
+
return tuple_by_end(atoms) if atoms.first.is_a?(ISO8601::Duration)
|
362
|
+
|
363
|
+
tuple_by_start(atoms)
|
344
364
|
end
|
345
365
|
|
346
366
|
def tuple_by_both(atoms)
|
@@ -351,9 +371,9 @@ module ISO8601
|
|
351
371
|
|
352
372
|
def tuple_by_end(atoms)
|
353
373
|
seconds = atoms.first.to_seconds(atoms.last)
|
354
|
-
[(atoms.last
|
374
|
+
[(atoms.last + seconds),
|
355
375
|
atoms.last,
|
356
|
-
seconds]
|
376
|
+
seconds.abs]
|
357
377
|
end
|
358
378
|
|
359
379
|
def tuple_by_start(atoms)
|
@@ -364,29 +384,12 @@ module ISO8601
|
|
364
384
|
end
|
365
385
|
|
366
386
|
def valid_atoms?(atoms)
|
367
|
-
|
368
|
-
"The pattern of a time interval can't be <duration>/<duration>") \
|
387
|
+
raise(ISO8601::Errors::UnknownPattern, "The pattern of a time interval can't be <duration>/<duration>") \
|
369
388
|
if atoms.all? { |x| x.is_a?(ISO8601::Duration) }
|
370
389
|
end
|
371
390
|
|
372
391
|
def valid_date_time?(time)
|
373
|
-
|
374
|
-
end
|
375
|
-
|
376
|
-
def self.valid_date_time?(time, message = 'Expected a ISO8601::DateTime')
|
377
|
-
return true if time.is_a?(ISO8601::DateTime)
|
378
|
-
|
379
|
-
fail(ISO8601::Errors::TypeError, message)
|
380
|
-
end
|
381
|
-
|
382
|
-
def self.guard_from_datetimes(atoms, message)
|
383
|
-
atoms.all? { |x| valid_date_time?(x, message) }
|
384
|
-
end
|
385
|
-
|
386
|
-
def self.guard_from_duration(atoms, message)
|
387
|
-
fail(ISO8601::Errors::TypeError, message) \
|
388
|
-
unless atoms.any? { |x| x.is_a?(ISO8601::Duration) } &&
|
389
|
-
atoms.any? { |x| x.is_a?(ISO8601::DateTime) }
|
392
|
+
valid_date_time?(time)
|
390
393
|
end
|
391
394
|
end
|
392
395
|
end
|
data/lib/iso8601/version.rb
CHANGED
data/lib/iso8601/weeks.rb
CHANGED
data/lib/iso8601/years.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module ISO8601
|
4
2
|
##
|
5
3
|
# A Years atom in a {ISO8601::Duration}
|
@@ -47,16 +45,18 @@ module ISO8601
|
|
47
45
|
##
|
48
46
|
# The amount of seconds
|
49
47
|
#
|
48
|
+
# TODO: Fractions of year will fail
|
49
|
+
#
|
50
50
|
# @param [ISO8601::DateTime, nil] base (nil) The base datetime to compute
|
51
51
|
# the year length.
|
52
52
|
#
|
53
53
|
# @return [Numeric]
|
54
54
|
def to_seconds(base = nil)
|
55
55
|
valid_base?(base)
|
56
|
+
return factor(base) * atom if base.nil?
|
57
|
+
target = ::Time.utc(base.year + atom.to_i, base.month, base.day, base.hour, base.minute, base.second)
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
::Time.utc(year(atom, base)) - ::Time.utc(base.year)
|
59
|
+
target - base.to_time
|
60
60
|
end
|
61
61
|
|
62
62
|
##
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
RSpec.describe ISO8601::Duration do
|
@@ -22,21 +20,13 @@ RSpec.describe ISO8601::Duration do
|
|
22
20
|
end
|
23
21
|
|
24
22
|
it "should raise a ISO8601::Errors::InvalidFraction for any invalid patterns" do
|
25
|
-
expect { ISO8601::Duration.new('
|
26
|
-
expect { ISO8601::Duration.new('P1.5Y1M') }.to raise_error(ISO8601::Errors::InvalidFractions)
|
27
|
-
expect { ISO8601::Duration.new('P1.5MT10.5S') }.to raise_error(ISO8601::Errors::InvalidFractions)
|
23
|
+
expect { ISO8601::Duration.new('PT10.5M10.5S') }.to raise_error(ISO8601::Errors::InvalidFractions)
|
28
24
|
end
|
29
25
|
|
30
26
|
it "should parse any allowed pattern" do
|
31
27
|
expect { ISO8601::Duration.new('P1Y') }.to_not raise_error
|
32
|
-
expect { ISO8601::Duration.new('P0.5Y') }.to_not raise_error
|
33
|
-
expect { ISO8601::Duration.new('P0,5Y') }.to_not raise_error
|
34
28
|
expect { ISO8601::Duration.new('P1Y1M') }.to_not raise_error
|
35
|
-
expect { ISO8601::Duration.new('P1Y0.5M') }.to_not raise_error
|
36
|
-
expect { ISO8601::Duration.new('P1Y0,5M') }.to_not raise_error
|
37
29
|
expect { ISO8601::Duration.new('P1Y1M1D') }.to_not raise_error
|
38
|
-
expect { ISO8601::Duration.new('P1Y1M0.5D') }.to_not raise_error
|
39
|
-
expect { ISO8601::Duration.new('P1Y1M0,5D') }.to_not raise_error
|
40
30
|
expect { ISO8601::Duration.new('P1Y1M1DT1H') }.to_not raise_error
|
41
31
|
expect { ISO8601::Duration.new('P1Y1M1DT0.5H') }.to_not raise_error
|
42
32
|
expect { ISO8601::Duration.new('P1Y1M1DT0,5H') }.to_not raise_error
|
@@ -268,8 +258,8 @@ RSpec.describe ISO8601::Duration do
|
|
268
258
|
end
|
269
259
|
|
270
260
|
it "should equal by hash identity" do
|
271
|
-
expect(ISO8601::Duration.new('PT1H').eql?
|
272
|
-
expect(ISO8601::Duration.new('PT1H').eql?
|
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
|
273
263
|
end
|
274
264
|
end
|
275
265
|
|
data/spec/iso8601/hours_spec.rb
CHANGED
@@ -5,17 +5,17 @@ RSpec.describe ISO8601::Hours do
|
|
5
5
|
let(:subject) { ISO8601::Hours.new(1) }
|
6
6
|
|
7
7
|
it "should respond to the Atomic interface" do
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -5,17 +5,17 @@ RSpec.describe ISO8601::Minutes do
|
|
5
5
|
let(:subject) { ISO8601::Minutes.new(1) }
|
6
6
|
|
7
7
|
it "should respond to the Atomic interface" do
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
19
|
end
|
20
20
|
end
|
21
21
|
|
data/spec/iso8601/months_spec.rb
CHANGED
@@ -7,21 +7,25 @@ RSpec.describe ISO8601::Months do
|
|
7
7
|
let(:common_february) { ISO8601::DateTime.new('2010-02-01') }
|
8
8
|
let(:leap_february) { ISO8601::DateTime.new('2000-02-01') }
|
9
9
|
|
10
|
+
let(:common_december) { ISO8601::DateTime.new('2017-12-01') }
|
11
|
+
let(:leap_december) { ISO8601::DateTime.new('2000-12-01') }
|
12
|
+
|
13
|
+
|
10
14
|
describe 'Atomic' do
|
11
15
|
let(:subject) { ISO8601::Months.new(1) }
|
12
16
|
|
13
17
|
it "should respond to the Atomic interface" do
|
14
|
-
[
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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) }
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -29,6 +33,7 @@ RSpec.describe ISO8601::Months do
|
|
29
33
|
it "should return the Month factor" do
|
30
34
|
expect { ISO8601::Months.new(1).factor }.to_not raise_error
|
31
35
|
expect(ISO8601::Months.new(2).factor).to eq(2628000)
|
36
|
+
expect(ISO8601::Months.new(0).factor).to eq(2628000)
|
32
37
|
end
|
33
38
|
|
34
39
|
it "should return the Month factor for a common year" do
|
@@ -55,6 +60,9 @@ RSpec.describe ISO8601::Months do
|
|
55
60
|
|
56
61
|
it "should return the amount of seconds for a common year" do
|
57
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)
|
58
66
|
end
|
59
67
|
|
60
68
|
it "should return the amount of seconds for a leap year" do
|
@@ -5,17 +5,17 @@ RSpec.describe ISO8601::Seconds do
|
|
5
5
|
let(:subject) { ISO8601::Seconds.new(1) }
|
6
6
|
|
7
7
|
it "should respond to the Atomic interface" do
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
RSpec.describe ISO8601::TimeInterval do
|
@@ -56,19 +54,13 @@ RSpec.describe ISO8601::TimeInterval do
|
|
56
54
|
context "allowed patterns" do
|
57
55
|
it "should parse <start>/<duration>" do
|
58
56
|
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y') }.to_not raise_error
|
59
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P0.5Y') }.to_not raise_error
|
60
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y0.5M') }.to_not raise_error
|
61
|
-
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y0,5M') }.to_not raise_error
|
62
57
|
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1D') }.to_not raise_error
|
63
58
|
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1DT1H1M1.0S') }.to_not raise_error
|
64
59
|
expect { ISO8601::TimeInterval.parse('2007-03-01T13:00:00Z/P1Y1M1DT1H1M1,0S') }.to_not raise_error
|
65
60
|
end
|
66
61
|
|
67
62
|
it "should parse <duration>/<end>" do
|
68
|
-
expect { ISO8601::TimeInterval.parse('P1Y0,5M/2010-05-09T10:30:12+04') }.to_not raise_error
|
69
63
|
expect { ISO8601::TimeInterval.parse('P1Y1M1D/2010-05-09T10:30:12+04:00') }.to_not raise_error
|
70
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M0.5D/2010-05-09T10:30:12-04:00') }.to_not raise_error
|
71
|
-
expect { ISO8601::TimeInterval.parse('P1Y1M0,5D/2010-05-09T10:30:12-00:00') }.to_not raise_error
|
72
64
|
expect { ISO8601::TimeInterval.parse('P1Y1M1DT1H/-2014-05-31T16:26:00Z') }.to_not raise_error
|
73
65
|
expect { ISO8601::TimeInterval.parse('P1Y1M1DT0.5H/2014-05-31T16:26:10.5Z') }.to_not raise_error
|
74
66
|
expect { ISO8601::TimeInterval.parse('P1Y1M1DT0,5H/2014-05-31T16:26:10,5Z') }.to_not raise_error
|
@@ -180,6 +172,107 @@ RSpec.describe ISO8601::TimeInterval do
|
|
180
172
|
expect(ISO8601::TimeInterval.parse(pattern2).first).to eq(start_time)
|
181
173
|
expect(ISO8601::TimeInterval.parse(pattern3).first).to eq(start_time)
|
182
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
|
+
|
183
276
|
end
|
184
277
|
|
185
278
|
describe "#last" do
|
@@ -207,8 +300,8 @@ RSpec.describe ISO8601::TimeInterval do
|
|
207
300
|
|
208
301
|
describe "#to_s" do
|
209
302
|
it "should return the pattern if TimeInterval is initialized with a pattern" do
|
210
|
-
pattern = 'P1Y1M1DT0,
|
211
|
-
pattern2 = '2007-03-01T13:00:00Z/
|
303
|
+
pattern = 'P1Y1M1DT0,5S/2014-05-31T16:26:10Z'
|
304
|
+
pattern2 = '2007-03-01T13:00:00Z/P1Y'
|
212
305
|
|
213
306
|
expect(ISO8601::TimeInterval.parse(pattern).to_s).to eq(pattern)
|
214
307
|
expect(ISO8601::TimeInterval.parse(pattern2).to_s).to eq(pattern2)
|
data/spec/iso8601/weeks_spec.rb
CHANGED
@@ -5,17 +5,17 @@ RSpec.describe ISO8601::Weeks do
|
|
5
5
|
let(:subject) { ISO8601::Weeks.new(1) }
|
6
6
|
|
7
7
|
it "should respond to the Atomic interface" do
|
8
|
-
[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
19
|
end
|
20
20
|
end
|
21
21
|
|
data/spec/iso8601/years_spec.rb
CHANGED
@@ -8,17 +8,17 @@ RSpec.describe ISO8601::Years do
|
|
8
8
|
let(:subject) { ISO8601::Years.new(1) }
|
9
9
|
|
10
10
|
it "should respond to the Atomic interface" do
|
11
|
-
[
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
%i[factor
|
12
|
+
to_seconds
|
13
|
+
symbol
|
14
|
+
to_i
|
15
|
+
to_f
|
16
|
+
to_s
|
17
|
+
value
|
18
|
+
<=>
|
19
|
+
eql?
|
20
|
+
hash
|
21
|
+
valid_atom?].each { |m| expect(subject).to respond_to(m) }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -31,6 +31,7 @@ RSpec.describe ISO8601::Years do
|
|
31
31
|
|
32
32
|
it "should return the Year factor for a common year" do
|
33
33
|
expect(ISO8601::Years.new(1).factor(common_year)).to eq(31536000)
|
34
|
+
expect(ISO8601::Years.new(0).factor(common_year)).to eq(31536000)
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should return the Year factor for a leap year" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso8601
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnau Siches
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.50'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.50'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.11.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.11.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-doc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.11.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.11.0
|
69
69
|
description: |2
|
70
70
|
ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and
|
71
71
|
interchange formats - Information interchange - Representation of dates
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project: iso8601
|
137
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.7.3
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601
|
@@ -152,4 +152,3 @@ test_files:
|
|
152
152
|
- spec/iso8601/weeks_spec.rb
|
153
153
|
- spec/iso8601/years_spec.rb
|
154
154
|
- spec/spec_helper.rb
|
155
|
-
has_rdoc: yard
|