iso8601 0.12.3 → 0.13.0
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/README.md +2 -4
- data/lib/iso8601.rb +2 -0
- data/lib/iso8601/atomic.rb +2 -0
- data/lib/iso8601/date.rb +4 -0
- data/lib/iso8601/date_time.rb +4 -0
- data/lib/iso8601/days.rb +2 -0
- data/lib/iso8601/duration.rb +6 -2
- data/lib/iso8601/errors.rb +2 -0
- data/lib/iso8601/hours.rb +2 -0
- data/lib/iso8601/minutes.rb +2 -0
- data/lib/iso8601/months.rb +3 -0
- data/lib/iso8601/seconds.rb +2 -0
- data/lib/iso8601/time.rb +5 -3
- data/lib/iso8601/time_interval.rb +2 -0
- data/lib/iso8601/version.rb +3 -1
- data/lib/iso8601/weeks.rb +2 -0
- data/lib/iso8601/years.rb +5 -0
- data/spec/iso8601/date_spec.rb +2 -0
- data/spec/iso8601/date_time_spec.rb +2 -0
- data/spec/iso8601/days_spec.rb +2 -0
- data/spec/iso8601/duration_spec.rb +2 -0
- data/spec/iso8601/hours_spec.rb +2 -0
- data/spec/iso8601/minutes_spec.rb +2 -0
- data/spec/iso8601/months_spec.rb +2 -0
- data/spec/iso8601/seconds_spec.rb +2 -0
- data/spec/iso8601/time_interval_spec.rb +2 -0
- data/spec/iso8601/time_spec.rb +2 -0
- data/spec/iso8601/weeks_spec.rb +2 -0
- data/spec/iso8601/years_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- metadata +32 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2974ec0c720d241b0a0911daf76b75ed14b3ebd6c7d7281928e378020dfead9c
|
4
|
+
data.tar.gz: 6b2259287505b9a2cbc55f45b0f79ba1d997398a415e905372c28736a3a3ac52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e5eaea339d00bd45c42e0851e2c53690752e845fd032df04f1fd56f459125af1153c1165a6871861e6b7ac7ce9814fdadd4e24081bdcc13aa03a44dd408947f
|
7
|
+
data.tar.gz: 6dc46e177556b17d5545e469fd624071db4dfbd914557b6c641b3bfec04e6af295d2f7c024940cb4777f4c78cb88a271c85147efed2a11299154227373c5bcf8
|
data/README.md
CHANGED
@@ -11,8 +11,6 @@ Version 1.0.0 will lock public interfaces.
|
|
11
11
|
|
12
12
|
Check the [changelog](https://github.com/arnau/ISO8601/blob/master/CHANGELOG.md) if you are upgrading from an older version.
|
13
13
|
|
14
|
-
[](https://gitter.im/arnau/ISO8601?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
15
|
-
|
16
14
|
ISO8601 is a simple implementation of the ISO 8601 (Data elements and
|
17
15
|
interchange formats — Information interchange — Representation of dates and
|
18
16
|
times) standard.
|
@@ -24,7 +22,7 @@ times) standard.
|
|
24
22
|
|
25
23
|
## Supported versions
|
26
24
|
|
27
|
-
* MRI 2.
|
25
|
+
* MRI 2.5, 2.6, 2.7
|
28
26
|
|
29
27
|
## Documentation
|
30
28
|
|
@@ -48,7 +46,7 @@ Then
|
|
48
46
|
|
49
47
|
```
|
50
48
|
$ bundle install
|
51
|
-
$ bundle exec
|
49
|
+
$ bundle exec rake
|
52
50
|
```
|
53
51
|
|
54
52
|
## Contributing
|
data/lib/iso8601.rb
CHANGED
data/lib/iso8601/atomic.rb
CHANGED
data/lib/iso8601/date.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A Date representation.
|
@@ -112,6 +114,7 @@ module ISO8601
|
|
112
114
|
# @param [String] input
|
113
115
|
#
|
114
116
|
# @return [Array<Integer>]
|
117
|
+
#
|
115
118
|
# rubocop:disable Metrics/AbcSize
|
116
119
|
def atomize(input)
|
117
120
|
week_date = parse_weekdate(input)
|
@@ -128,6 +131,7 @@ module ISO8601
|
|
128
131
|
|
129
132
|
[year, month, day].compact.map(&:to_i)
|
130
133
|
end
|
134
|
+
# rubocop:enable Metrics/AbcSize
|
131
135
|
|
132
136
|
def parse_weekdate(input)
|
133
137
|
/^([+-]?)\d{4}(-?)W\d{2}(?:\2\d)?$/.match(input)
|
data/lib/iso8601/date_time.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A DateTime representation
|
@@ -96,6 +98,7 @@ module ISO8601
|
|
96
98
|
# It enhances the parsing capabilities of the native DateTime.
|
97
99
|
#
|
98
100
|
# @param [String] date_time The ISO representation
|
101
|
+
#
|
99
102
|
# rubocop:disable Metrics/AbcSize
|
100
103
|
def parse(date_time)
|
101
104
|
raise(ISO8601::Errors::UnknownPattern, date_time) if date_time.empty?
|
@@ -111,6 +114,7 @@ module ISO8601
|
|
111
114
|
|
112
115
|
::DateTime.new(*(date_atoms + time_atoms).compact)
|
113
116
|
end
|
117
|
+
# rubocop:enable Metrics/AbcSize
|
114
118
|
|
115
119
|
##
|
116
120
|
# Validates the date has the right pattern.
|
data/lib/iso8601/days.rb
CHANGED
data/lib/iso8601/duration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A duration representation. When no base is provided, all atoms use an
|
@@ -21,8 +23,6 @@ module ISO8601
|
|
21
23
|
# dp = ISO8601::Duration.new('P2Y1MT2H')
|
22
24
|
# di == dp # => true
|
23
25
|
# di == ds # => true
|
24
|
-
#
|
25
|
-
# rubocop:disable Metrics/ClassLength
|
26
26
|
class Duration
|
27
27
|
##
|
28
28
|
# @param [String, Numeric] input The duration pattern
|
@@ -244,6 +244,7 @@ module ISO8601
|
|
244
244
|
# @param [Numeric] value The seconds to promote
|
245
245
|
#
|
246
246
|
# @return [ISO8601::Duration]
|
247
|
+
#
|
247
248
|
# rubocop:disable Metrics/AbcSize
|
248
249
|
def seconds_to_iso(value)
|
249
250
|
return self.class.new('PT0S') if value.zero?
|
@@ -263,6 +264,7 @@ module ISO8601
|
|
263
264
|
|
264
265
|
self.class.new(date + time)
|
265
266
|
end
|
267
|
+
# rubocop:enable Metrics/AbcSize
|
266
268
|
|
267
269
|
def decompose_atom(value, atom)
|
268
270
|
[atom.class.new((value / atom.factor).to_i), (value % atom.factor)]
|
@@ -282,6 +284,7 @@ module ISO8601
|
|
282
284
|
input
|
283
285
|
end
|
284
286
|
|
287
|
+
# rubocop:disable Metrics/AbcSize
|
285
288
|
def valid_pattern?(components)
|
286
289
|
date = [components[:years],
|
287
290
|
components[:months],
|
@@ -297,6 +300,7 @@ module ISO8601
|
|
297
300
|
|
298
301
|
raise(ISO8601::Errors::UnknownPattern, @pattern) if empty
|
299
302
|
end
|
303
|
+
# rubocop:enable Metrics/AbcSize
|
300
304
|
|
301
305
|
def valid_fractions?(values)
|
302
306
|
values = values.reject(&:zero?)
|
data/lib/iso8601/errors.rb
CHANGED
data/lib/iso8601/hours.rb
CHANGED
data/lib/iso8601/minutes.rb
CHANGED
data/lib/iso8601/months.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A Months atom in a {ISO8601::Duration}
|
@@ -81,5 +83,6 @@ module ISO8601
|
|
81
83
|
|
82
84
|
(::Time.utc(year, month) - ::Time.utc(base.year, base.month)) / atom
|
83
85
|
end
|
86
|
+
# rubocop:enable Metrics/AbcSize
|
84
87
|
end
|
85
88
|
end
|
data/lib/iso8601/seconds.rb
CHANGED
data/lib/iso8601/time.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A Time representation
|
@@ -113,6 +115,7 @@ module ISO8601
|
|
113
115
|
# @param [String] input
|
114
116
|
#
|
115
117
|
# @return [Array<Integer, Float>]
|
118
|
+
#
|
116
119
|
# rubocop:disable Metrics/AbcSize
|
117
120
|
def atomize(input)
|
118
121
|
_, time, zone = parse_timezone(input)
|
@@ -133,6 +136,7 @@ module ISO8601
|
|
133
136
|
|
134
137
|
atoms
|
135
138
|
end
|
139
|
+
# rubocop:enable Metrics/AbcSize
|
136
140
|
|
137
141
|
def require_separator(input)
|
138
142
|
!input.nil?
|
@@ -164,9 +168,7 @@ module ISO8601
|
|
164
168
|
_, offset, separator = zone_regexp.match(zone).to_a.compact
|
165
169
|
|
166
170
|
wrong_pattern = !zone.nil? && offset.nil?
|
167
|
-
if require_separator
|
168
|
-
invalid_separators = zone.to_s.match(/^[+-]\d{2}:?\d{2}$/) && (@separator != separator)
|
169
|
-
end
|
171
|
+
invalid_separators = zone.to_s.match(/^[+-]\d{2}:?\d{2}$/) && (@separator != separator) if require_separator
|
170
172
|
|
171
173
|
!(wrong_pattern || invalid_separators)
|
172
174
|
end
|
data/lib/iso8601/version.rb
CHANGED
data/lib/iso8601/weeks.rb
CHANGED
data/lib/iso8601/years.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ISO8601
|
2
4
|
##
|
3
5
|
# A Years atom in a {ISO8601::Duration}
|
@@ -51,14 +53,17 @@ module ISO8601
|
|
51
53
|
# the year length.
|
52
54
|
#
|
53
55
|
# @return [Numeric]
|
56
|
+
#
|
54
57
|
# rubocop:disable Metrics/AbcSize
|
55
58
|
def to_seconds(base = nil)
|
56
59
|
valid_base?(base)
|
57
60
|
return factor(base) * atom if base.nil?
|
61
|
+
|
58
62
|
target = ::Time.new(base.year + atom.to_i, base.month, base.day, base.hour, base.minute, base.second, base.zone)
|
59
63
|
|
60
64
|
target - base.to_time
|
61
65
|
end
|
66
|
+
# rubocop:enable Metrics/AbcSize
|
62
67
|
|
63
68
|
##
|
64
69
|
# The atom symbol.
|
data/spec/iso8601/date_spec.rb
CHANGED
data/spec/iso8601/days_spec.rb
CHANGED
data/spec/iso8601/hours_spec.rb
CHANGED
data/spec/iso8601/months_spec.rb
CHANGED
data/spec/iso8601/time_spec.rb
CHANGED
data/spec/iso8601/weeks_spec.rb
CHANGED
data/spec/iso8601/years_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso8601
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.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: 2020-07-
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: pry
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.13.1
|
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:
|
26
|
+
version: 0.13.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry-doc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.1.0
|
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:
|
40
|
+
version: 1.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '13.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: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '3.9'
|
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:
|
68
|
+
version: '3.9'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '0.85'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '0.85'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-packaging
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.1.1
|
83
97
|
description: |2
|
84
98
|
ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and
|
85
99
|
interchange formats - Information interchange - Representation of dates
|
@@ -136,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
150
|
requirements:
|
137
151
|
- - ">="
|
138
152
|
- !ruby/object:Gem::Version
|
139
|
-
version: 2.
|
153
|
+
version: 2.4.0
|
140
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
155
|
requirements:
|
142
156
|
- - ">="
|