iso8601 0.12.0 → 0.12.1
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/iso8601.gemspec +3 -41
- data/lib/iso8601/version.rb +1 -1
- metadata +8 -34
- data/CHANGELOG.md +0 -114
- 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 -299
- data/spec/iso8601/hours_spec.rb +0 -44
- data/spec/iso8601/minutes_spec.rb +0 -44
- data/spec/iso8601/months_spec.rb +0 -98
- data/spec/iso8601/seconds_spec.rb +0 -44
- data/spec/iso8601/time_interval_spec.rb +0 -520
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b275dd85921d3d5a18dd4cbecaeb2f7a7c5c76e2527030087e00d971c2fb2ba8
|
4
|
+
data.tar.gz: 2ad804505434c8fd15e52298915cf191b1a6d5529c069a65cb418bb3f92b9719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88d158b64e8e9958b69263593a7606000d50dc254fb1ef929a0544ed4d2881ebea16b37aa5638082a866a148d2aab28c7ab2680703e05f8a480deb44590e9f8b
|
7
|
+
data.tar.gz: 15591902cd2de0debe9b4b1c2f8c2a4568ff9fdaf35372d88183d5f8a81a3f245c6ac3b871e5dda621b0b75674f6f8b494e55581f93fa476f5e2cd8a7adb3abd
|
data/iso8601.gemspec
CHANGED
@@ -17,49 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
DESC
|
18
18
|
s.license = 'MIT'
|
19
19
|
s.rubyforge_project = 'iso8601'
|
20
|
-
s.files =
|
21
|
-
|
22
|
-
Gemfile
|
23
|
-
LICENSE
|
24
|
-
README.md
|
25
|
-
Rakefile
|
26
|
-
iso8601.gemspec
|
27
|
-
docs/date-time.md
|
28
|
-
docs/duration.md
|
29
|
-
docs/time-interval.md
|
30
|
-
lib/iso8601.rb
|
31
|
-
lib/iso8601/atomic.rb
|
32
|
-
lib/iso8601/date.rb
|
33
|
-
lib/iso8601/date_time.rb
|
34
|
-
lib/iso8601/days.rb
|
35
|
-
lib/iso8601/duration.rb
|
36
|
-
lib/iso8601/errors.rb
|
37
|
-
lib/iso8601/hours.rb
|
38
|
-
lib/iso8601/minutes.rb
|
39
|
-
lib/iso8601/months.rb
|
40
|
-
lib/iso8601/seconds.rb
|
41
|
-
lib/iso8601/time.rb
|
42
|
-
lib/iso8601/time_interval.rb
|
43
|
-
lib/iso8601/version.rb
|
44
|
-
lib/iso8601/weeks.rb
|
45
|
-
lib/iso8601/years.rb
|
46
|
-
spec/iso8601/date_spec.rb
|
47
|
-
spec/iso8601/date_time_spec.rb
|
48
|
-
spec/iso8601/days_spec.rb
|
49
|
-
spec/iso8601/duration_spec.rb
|
50
|
-
spec/iso8601/hours_spec.rb
|
51
|
-
spec/iso8601/minutes_spec.rb
|
52
|
-
spec/iso8601/months_spec.rb
|
53
|
-
spec/iso8601/seconds_spec.rb
|
54
|
-
spec/iso8601/time_interval_spec.rb
|
55
|
-
spec/iso8601/time_spec.rb
|
56
|
-
spec/iso8601/weeks_spec.rb
|
57
|
-
spec/iso8601/years_spec.rb
|
58
|
-
spec/spec_helper.rb]
|
59
|
-
s.test_files = s.files.grep(%r{^spec/})
|
20
|
+
s.files = %w{LICENSE README.md CONTRIBUTING.md} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:lib/)}i }
|
21
|
+
s.test_files = %w{Rakefile iso8601.gemspec Gemfile} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:specs/)}i }
|
60
22
|
s.require_paths = ['lib']
|
61
23
|
|
62
|
-
s.
|
24
|
+
s.metadata["yard.run"] = "yri"
|
63
25
|
s.required_ruby_version = '>= 2.0.0'
|
64
26
|
s.add_development_dependency 'rspec', '~> 3.6'
|
65
27
|
s.add_development_dependency 'rubocop', '~> 0.50'
|
data/lib/iso8601/version.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.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnau Siches
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -75,15 +75,11 @@ executables: []
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- CHANGELOG.md
|
79
78
|
- CONTRIBUTING.md
|
80
79
|
- Gemfile
|
81
80
|
- LICENSE
|
82
81
|
- README.md
|
83
82
|
- Rakefile
|
84
|
-
- docs/date-time.md
|
85
|
-
- docs/duration.md
|
86
|
-
- docs/time-interval.md
|
87
83
|
- iso8601.gemspec
|
88
84
|
- lib/iso8601.rb
|
89
85
|
- lib/iso8601/atomic.rb
|
@@ -101,23 +97,11 @@ files:
|
|
101
97
|
- lib/iso8601/version.rb
|
102
98
|
- lib/iso8601/weeks.rb
|
103
99
|
- lib/iso8601/years.rb
|
104
|
-
- spec/iso8601/date_spec.rb
|
105
|
-
- spec/iso8601/date_time_spec.rb
|
106
|
-
- spec/iso8601/days_spec.rb
|
107
|
-
- spec/iso8601/duration_spec.rb
|
108
|
-
- spec/iso8601/hours_spec.rb
|
109
|
-
- spec/iso8601/minutes_spec.rb
|
110
|
-
- spec/iso8601/months_spec.rb
|
111
|
-
- spec/iso8601/seconds_spec.rb
|
112
|
-
- spec/iso8601/time_interval_spec.rb
|
113
|
-
- spec/iso8601/time_spec.rb
|
114
|
-
- spec/iso8601/weeks_spec.rb
|
115
|
-
- spec/iso8601/years_spec.rb
|
116
|
-
- spec/spec_helper.rb
|
117
100
|
homepage: https://github.com/arnau/ISO8601
|
118
101
|
licenses:
|
119
102
|
- MIT
|
120
|
-
metadata:
|
103
|
+
metadata:
|
104
|
+
yard.run: yri
|
121
105
|
post_install_message:
|
122
106
|
rdoc_options: []
|
123
107
|
require_paths:
|
@@ -134,21 +118,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
118
|
version: '0'
|
135
119
|
requirements: []
|
136
120
|
rubyforge_project: iso8601
|
137
|
-
rubygems_version: 2.7.
|
121
|
+
rubygems_version: 2.7.7
|
138
122
|
signing_key:
|
139
123
|
specification_version: 4
|
140
124
|
summary: Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601
|
141
125
|
test_files:
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
- spec/iso8601/duration_spec.rb
|
146
|
-
- spec/iso8601/hours_spec.rb
|
147
|
-
- spec/iso8601/minutes_spec.rb
|
148
|
-
- spec/iso8601/months_spec.rb
|
149
|
-
- spec/iso8601/seconds_spec.rb
|
150
|
-
- spec/iso8601/time_interval_spec.rb
|
151
|
-
- spec/iso8601/time_spec.rb
|
152
|
-
- spec/iso8601/weeks_spec.rb
|
153
|
-
- spec/iso8601/years_spec.rb
|
154
|
-
- spec/spec_helper.rb
|
126
|
+
- Rakefile
|
127
|
+
- iso8601.gemspec
|
128
|
+
- Gemfile
|
data/CHANGELOG.md
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
## 0.12.0
|
2
|
-
|
3
|
-
* Fix `Months#to_seconds` from November (thanks @walterbrebels).
|
4
|
-
|
5
|
-
## 0.11.0
|
6
|
-
|
7
|
-
* Add support for unary minus operator (thanks @walterbrebels).
|
8
|
-
|
9
|
-
## 0.10.1
|
10
|
-
|
11
|
-
* Fix `TimeInterval` size for non UTC timezones. (#41)
|
12
|
-
|
13
|
-
## 0.10.0
|
14
|
-
|
15
|
-
* Fix `TimeInterval` with `<duration>/<end>` patterns and leap years.
|
16
|
-
* Fix decimal fractions on date atoms. **WARNING** some duration patterns are
|
17
|
-
no longer valid.
|
18
|
-
|
19
|
-
## 0.9.1
|
20
|
-
|
21
|
-
* Fix `Duration#to_pattern` for negative durations based on a `Numeric` (thanks @figwit).
|
22
|
-
|
23
|
-
## 0.9.0
|
24
|
-
|
25
|
-
This version is **not compatible** with previous versions. Atoms and Durations
|
26
|
-
changed their interface when treating base dates so it is only applied when
|
27
|
-
computing the Atom length (e.g. `#to_seconds`). As a consequence, it is no
|
28
|
-
longer possible to do operations like `DateTime + Duration`.
|
29
|
-
|
30
|
-
* Add time intervals (thanks @Angelmmiguel).
|
31
|
-
* Remove `Duration#to_i`.
|
32
|
-
* Change `Duration#to_seconds` to accept a base `DateTime`.
|
33
|
-
* Remove duration dependency on a base date on the instance level.
|
34
|
-
* Change `Years#to_seconds` and `Months#to_seconds` to accept a base `DateTime`.
|
35
|
-
* Remove atom dependency on a base date on the instance level.
|
36
|
-
* Add `Atomic` mixin.
|
37
|
-
* Remove `Atom` abstract class.
|
38
|
-
* Allow `ISO8601::Duration` to perform operations with `Numeric` (thanks @Angelmmiguel).
|
39
|
-
|
40
|
-
## 0.8.7
|
41
|
-
|
42
|
-
* Make `Atom` comparable with the same kind (thanks @glassbead0).
|
43
|
-
* Fix #18 document interfaces to core date/time classes.
|
44
|
-
|
45
|
-
## 0.8.6
|
46
|
-
|
47
|
-
* Fix #26 operations with Date, DateTime and Time with Duration (e.g. `ISO8601::DateTime.new('2012-07-07T20:20:20Z') - ISO8601::Duration.new('PT10M')`).
|
48
|
-
* Fix #25 accept time components with timezone and only hour component (e.g. `ISO8601::Time.new('T10+01:00')`).
|
49
|
-
* Fix Docker image for testing and inspecting.
|
50
|
-
|
51
|
-
## 0.8.5
|
52
|
-
|
53
|
-
* Fix `DateTime#hash`
|
54
|
-
* Fix `DateTime#second` and `Time#second` precision. Now it's rounded to the
|
55
|
-
first decimal.
|
56
|
-
|
57
|
-
## 0.8.4
|
58
|
-
|
59
|
-
* Remove unwanted log.
|
60
|
-
|
61
|
-
## 0.8.3
|
62
|
-
|
63
|
-
* Fix partial time patterns with timezone: `PThh:mmZ`, `PThhZ`.
|
64
|
-
|
65
|
-
## 0.8.2
|
66
|
-
|
67
|
-
* Fix time components using comma (,) as a decimal separator.
|
68
|
-
|
69
|
-
## 0.8.1
|
70
|
-
|
71
|
-
* Fix durations using comma (,) as a decimal separator.
|
72
|
-
|
73
|
-
## 0.8.0
|
74
|
-
|
75
|
-
* `DateTime` has hash identity by value.
|
76
|
-
* `Time` has hash identity by value.
|
77
|
-
* `Date` has hash identity by value.
|
78
|
-
* `Duration` has hash identity by value.
|
79
|
-
* `Atom` has hash identity by value.
|
80
|
-
* `Atom#value` returns either an integer or a float.
|
81
|
-
* `Atom#to_s` returns a valid ISO8601 subpattern.
|
82
|
-
|
83
|
-
## 0.7.0
|
84
|
-
|
85
|
-
* Add decimal fractions for any component in a duration.
|
86
|
-
* Add a catch all `ISO8601::Errors::StandardError`.
|
87
|
-
* Add support for comma (`,`) as a separator for duration decimal fractions.
|
88
|
-
|
89
|
-
## 0.6.0
|
90
|
-
|
91
|
-
* Add `#hash` to `Duration`, `Date`, `Time` and `DateTime`.
|
92
|
-
|
93
|
-
## 0.5.2
|
94
|
-
|
95
|
-
* Fix `DateTime` when handling empty strings.
|
96
|
-
|
97
|
-
## 0.5.1
|
98
|
-
|
99
|
-
* Fix durations with sign.
|
100
|
-
|
101
|
-
## 0.5.0
|
102
|
-
|
103
|
-
* Drop support for Ruby 1.8.7.
|
104
|
-
* Add support for Rubinius 2.
|
105
|
-
* `ISO8601::DateTime#century` no longer exists. Truncated representations were
|
106
|
-
removed in ISO 8601:2004.
|
107
|
-
* `ISO8601::DateTime#zone` delegates to core `DateTime#zone`.
|
108
|
-
* `ISO8601::DateTime#timezone` no longer exists. Now it delegates to
|
109
|
-
`DateTime#zone`.
|
110
|
-
* A date can have sign: `-1000-01-01`, `+2014-05-06T10:11:12Z`.
|
111
|
-
* A date time can be converted to an array of atoms with `#to_a`.
|
112
|
-
* Ordinal dates supported.
|
113
|
-
* A date component is represented by `ISO8601::Date`.
|
114
|
-
* Week date pattern (YYYY-Wdww, YYYY-Www-D).
|
data/docs/date-time.md
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# Date Time, Date, Time
|
2
|
-
|
3
|
-
|
4
|
-
## Interface with core classes
|
5
|
-
|
6
|
-
ISO8601 classes provide a method `to_*` to convert to its core equivalent:
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
ISO8601::DateTime#to_datetime # => #<DateTime: ...>
|
10
|
-
ISO8601::Date#to_date # => #<Date: ...>
|
11
|
-
ISO8601::Time#to_time # => #<Time: ...>
|
12
|
-
```
|
13
|
-
|
14
|
-
## Differences with core Date, Time and DateTime
|
15
|
-
|
16
|
-
### Reduced precision
|
17
|
-
|
18
|
-
Core `Date.parse` and `DateTime.parse` don't allow reduced precision. For
|
19
|
-
example:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
DateTime.parse('2014-05') # => ArgumentError: invalid date
|
23
|
-
```
|
24
|
-
|
25
|
-
But the standard covers this situation assuming any missing token as its lower
|
26
|
-
value:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
ISO8601::DateTime.new('2014-05').to_s # => "2014-05-01T00:00:00+00:00"
|
30
|
-
ISO8601::DateTime.new('2014').to_s # => "2014-01-01T00:00:00+00:00"
|
31
|
-
```
|
32
|
-
|
33
|
-
The same assumption happens in core classes with `.new`:
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
DateTime.new(2014,5) # => #<DateTime: 2014-05-01T00:00:00+00:00 ((2456779j,0s,0n),+0s,2299161j)>
|
37
|
-
DateTime.new(2014) # => #<DateTime: 2014-01-01T00:00:00+00:00 ((2456659j,0s,0n),+0s,2299161j)>
|
38
|
-
```
|
39
|
-
|
40
|
-
### Unmatched precision
|
41
|
-
|
42
|
-
Unmatched precison is handled strongly. Notice the time fragment is lost in
|
43
|
-
`DateTime.parse` with no warning only if the loose precision is in the time
|
44
|
-
component.
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
ISO8601::DateTime.new('2014-05-06T101112') # => ISO8601::Errors::UnknownPattern
|
48
|
-
DateTime.parse('2014-05-06T101112') # => #<DateTime: 2014-05-06T00:00:00+00:00 ((2456784j,0s,0n),+0s,2299161j)>
|
49
|
-
|
50
|
-
ISO8601::DateTime.new('20140506T10:11:12') # => ISO8601::Errors::UnknownPattern
|
51
|
-
DateTime.parse('20140506T10:11:12') # => #<DateTime: 2014-05-06T10:11:12+00:00 ((2456784j,0s,0n),+0s,2299161j)>
|
52
|
-
```
|
53
|
-
|
54
|
-
### Strong pattern matching
|
55
|
-
|
56
|
-
Week dates raise an error when two digit days provied instead of return monday:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
ISO8601::DateTime.new('2014-W15-02') # => ISO8601::Errors::UnknownPattern
|
60
|
-
DateTime.new('2014-W15-02') # => #<Date: 2014-04-07 ((2456755j,0s,0n),+0s,2299161j)>
|
61
|
-
```
|
62
|
-
|
63
|
-
|
64
|
-
## Atomization
|
65
|
-
|
66
|
-
`DateTime#to_a` allows decomposing to an array of atoms:
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
atoms = ISO8601::DateTime.new('2014-05-31T10:11:12Z').to_a # => [2014, 5, 31, 10, 11, 12, '+00:00']
|
70
|
-
dt = DateTime.new(*atoms)
|
71
|
-
```
|
72
|
-
|
73
|
-
## Sign
|
74
|
-
|
75
|
-
Ordinal dates keep the sign. `2014-001` is not the same as `-2014-001`.
|
76
|
-
|
77
|
-
|
78
|
-
## Fractional seconds precision
|
79
|
-
|
80
|
-
Fractional seconds for `ISO8601::DateTime` and `ISO8601::Time` are rounded to
|
81
|
-
one decimal.
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
ISO8601::DateTime.new('2015-02-03T10:11:12.12').second #=> 12.1
|
85
|
-
ISO8601::Time.new('T10:11:12.16').second #=> 12.2
|
86
|
-
```
|
data/docs/duration.md
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# Duration
|
2
|
-
|
3
|
-
> Durations are a component of time intervals and define the amount of
|
4
|
-
> intervening time in a time interval. Source: [Wikipedia ISO8601](https://en.wikipedia.org/wiki/ISO_8601#Durations)
|
5
|
-
|
6
|
-
See [Time Interval](time-interval.md) for working with specific intervals of
|
7
|
-
time.
|
8
|
-
|
9
|
-
## Supported patterns
|
10
|
-
|
11
|
-
```
|
12
|
-
PnYnMnDTnHnMnS
|
13
|
-
PnW
|
14
|
-
```
|
15
|
-
|
16
|
-
`P<date>T<time>` will not be implemented.
|
17
|
-
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
Some times using durations might be more convenient than using time intervals:
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
duration = ISO8601::Duration.new('PT10H')
|
25
|
-
duration.to_seconds # => 36000.0
|
26
|
-
```
|
27
|
-
|
28
|
-
You can reuse the duration with a time interval:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
start_time = ISO8601::DateTime.new('2015-01-01T10:11:12Z')
|
32
|
-
time_interval = ISO8601::TimeInterval.from_duration(start_time, duration)
|
33
|
-
time_interval.size # => 36000.0
|
34
|
-
end_time = ISO8601::DateTime.new('2015-01-01T10:11:12Z')
|
35
|
-
time_interval = ISO8601::TimeInterval.from_duration(duration, end_time)
|
36
|
-
```
|
37
|
-
|
38
|
-
Or use an ad-hoc base:
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
base = ISO8601::DateTime.new('2015-01-01T10:11:12Z')
|
42
|
-
duration = ISO8601::Duration.new('PT10H')
|
43
|
-
duration.to_seconds(base) # => 36000.0
|
44
|
-
```
|
45
|
-
|
46
|
-
**Warning**: When using durations without base, the result of `#to_seconds` is
|
47
|
-
an _average_. See the atoms' implementation for details.
|
48
|
-
|
49
|
-
|
50
|
-
# Operate with durations
|
51
|
-
|
52
|
-
The `ISO8601::Duration` has the concept of sign to be able to represent negative
|
53
|
-
values:
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
(ISO8601::Duration.new('PT10S') - ISO8601::Duration.new('PT12S')).to_s #=> '-PT2S'
|
57
|
-
(ISO8601::Duration.new('-PT10S') + ISO8601::Duration.new('PT12S')).to_s #=> 'PT2S'
|
58
|
-
```
|
59
|
-
|
60
|
-
You can also inspect a duration by atom:
|
61
|
-
|
62
|
-
```
|
63
|
-
duration = ISO8601::Duration.new('P2Y1MT2H')
|
64
|
-
duration.years # => #<ISO8601::Years ... @atom=2.0>
|
65
|
-
duration.months # => #<ISO8601::Months ... @atom=1.0>
|
66
|
-
duration.days # => #<ISO8601::Days ... @atom=0>
|
67
|
-
duration.hours # => #<ISO8601::Hours ... @atom=2.0>
|
68
|
-
duration.minutes # => #<ISO8601::Hours ... @atom=0.0>
|
69
|
-
duration.seconds # => #<ISO8601::Hours ... @atom=0.0>
|
70
|
-
```
|
71
|
-
|
72
|
-
Or get back the pattern:
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
duration.to_s # => 'P2Y1MT2H'
|
76
|
-
```
|
data/docs/time-interval.md
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# Time Interval
|
2
|
-
|
3
|
-
> A time interval is the intervening time between two time points.
|
4
|
-
Source: [Wikipedia ISO8601](https://en.wikipedia.org/wiki/ISO_8601#Time_intervals)
|
5
|
-
|
6
|
-
This library implements the Time Interval type via [`ISO8601::TimeInterval`](../lib/iso8601/time_interval.rb)
|
7
|
-
with the following constructors:
|
8
|
-
|
9
|
-
* `TimeInterval.new(String)` (or `TimeInterval.parse(String)`)
|
10
|
-
* `TimeInterval.from_duration(Duration, Hash<DateTime>)`
|
11
|
-
* `TimeInterval.from_datetime(DateTime, DateTime)`
|
12
|
-
|
13
|
-
|
14
|
-
## Supported patterns
|
15
|
-
|
16
|
-
```
|
17
|
-
<start>/<end>
|
18
|
-
<start>/<duration>
|
19
|
-
<duration>/<end>
|
20
|
-
```
|
21
|
-
|
22
|
-
Where `<start>` and `<end>` are points in time and `<duration>` is an amount of
|
23
|
-
time.
|
24
|
-
|
25
|
-
The pattern `<duration>` is not implemented; instead, you can use
|
26
|
-
[`TimeInterval.from_duration`](../lib/iso8601/time_interval.rb#L70).
|
27
|
-
|
28
|
-
|
29
|
-
## Usage
|
30
|
-
|
31
|
-
### `<start>/<end>`
|
32
|
-
|
33
|
-
The resulting time interval will have a starting point based on the provided
|
34
|
-
`<start>` pattern and an ending point based on the provided `<end>` pattern.
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
ti = ISO8601::TimeInterval.parse('2015-12-12T19:53:00Z/2015-12-13T19:53:00Z')
|
38
|
-
ti.start_time.to_s # => '2015-12-12T19:53:00Z'
|
39
|
-
ti.end_time.to_s # => '2015-12-13T19:53:00Z'
|
40
|
-
ti.size # => 86_400.0
|
41
|
-
```
|
42
|
-
|
43
|
-
### `<start>/<duration>`
|
44
|
-
|
45
|
-
The resulting time interval will have a starting point based on the provided
|
46
|
-
`<start>` pattern and an ending point result of `<start> + <duration>`.
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
ti = ISO8601::TimeInterval.parse('2015-12-12T19:53:00Z/P1D')
|
50
|
-
ti.start_time.to_s # => '2015-12-12T19:53:00Z'
|
51
|
-
ti.end_time.to_s # => '2015-12-13T19:53:00Z'
|
52
|
-
ti.size # => 86_400.0
|
53
|
-
```
|
54
|
-
|
55
|
-
### `<duration>/<end>`
|
56
|
-
|
57
|
-
The resulting time interval will have a starting point result of
|
58
|
-
`<end> - <duration>` and an ending point based on the provided `<end>` pattern.
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
ti = ISO8601::TimeInterval.parse('P1D/2015-12-13T19:53:00Z')
|
62
|
-
ti.start_time.to_s # => '2015-12-12T19:53:00Z'
|
63
|
-
ti.end_time.to_s # => '2015-12-13T19:53:00Z'
|
64
|
-
ti.size # => 86_400.0
|
65
|
-
```
|
66
|
-
|
67
|
-
|
68
|
-
### `TimeInterval.from_duration`
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
duration = ISO8601::Duration.new('P1D`)
|
72
|
-
start_time = ISO8601::DateTime.new('2015-12-12T19:53:00Z')
|
73
|
-
ti = ISO8601::TimeInterval.from_duration(start_time, duration)
|
74
|
-
ti.start_time.to_s # => '2015-12-12T19:53:00Z'
|
75
|
-
ti.end_time.to_s # => '2015-12-13T19:53:00Z'
|
76
|
-
ti.size # => 86_400.0
|
77
|
-
|
78
|
-
|
79
|
-
end_time = ISO8601::DateTime.new('2015-12-13T19:53:00Z')
|
80
|
-
ti2 = ISO8601::TimeInterval.from_duration(duration, end_time)
|
81
|
-
ti2.start_time.to_s # => '2015-12-12T19:53:00Z'
|
82
|
-
ti2.end_time.to_s # => '2015-12-13T19:53:00Z'
|
83
|
-
ti2.size # => 86_400.0
|
84
|
-
```
|
85
|
-
|
86
|
-
### `TimeInterval.from_datetime`
|
87
|
-
|
88
|
-
This constructor is an alternative way to `<start>/<end>` via Ruby objects.
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
start_time = ISO8601::DateTime.new('2015-12-12T19:53:00Z')
|
92
|
-
end_time = ISO8601::DateTime.new('2015-12-13T19:53:00Z')
|
93
|
-
ti2 = ISO8601::TimeInterval.from_duration(start_time, end_time)
|
94
|
-
ti2.start_time.to_s # => '2015-12-12T19:53:00Z'
|
95
|
-
ti2.end_time.to_s # => '2015-12-13T19:53:00Z'
|
96
|
-
ti2.size # => 86_400.0
|
97
|
-
```
|
98
|
-
|
99
|
-
## Operate with time intervals
|
100
|
-
|
101
|
-
`TimeInterval` is `Comparable`, so you can use the usual `<`, `>`, `<=`, `>=`,
|
102
|
-
`==` to compare against another `TimeInterval`. Is equivalent to get the
|
103
|
-
amount of seconds via `#to_f` and compare the resulting numbers.
|
104
|
-
|
105
|
-
A time interval can be viewed as an ordered set of datetime elements:
|
106
|
-
|
107
|
-
* `#empty?` checks if an interval is empty.
|
108
|
-
* `#include?` checks if a `DateTime` is part of the time interval.
|
109
|
-
* `#intersect?` checks if two time intervals overlap.
|
110
|
-
* `#intersection` returns the intersected time interval if the two intervals intersect.
|
111
|
-
* `#disjoint?` checks if two time intervals don't intersect.
|
112
|
-
* `#subset?` checks if a time interval is included in another one.
|
113
|
-
* `#superset?` checks if a time interval is included in another one.
|
114
|
-
* `#first` is the lower bound.
|
115
|
-
* `#last` is the upper bound.
|
116
|
-
* `#size` is the total amount of seconds.
|
117
|
-
|
118
|
-
|
119
|
-
You can convert a time interval into a string with `#to_s` or into a float via
|
120
|
-
`#to_f`.
|