time-interval 0.0.4 → 0.0.5
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/.travis.yml +4 -0
- data/README.md +42 -5
- data/Rakefile +10 -0
- data/lib/time_interval.rb +1 -1
- data/lib/time_interval/version.rb +1 -1
- data/spec/lib/time_interval_spec.rb +5 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e89712672c6ec5639335d9c1370a78f67030b5c0
|
4
|
+
data.tar.gz: 4b7c895953c7c6d1ef260fc043036f655554fe62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100dfbfce1a5415ad1366f69ae58f2d5a81fbd826d393d41e5531ad634c620eb127877b6526ff5e44c078efc33fbeca945151d82c9b60081dd9933463bf8aa70
|
7
|
+
data.tar.gz: 50fd4595f04cb6fd2b81599e20454c2aa9897f2e6b159d4ae33ea2bb142e00740f254b01d5d0c826400f5c224ed30ebf8f546bba6cce846aae5a7ab9f882a863
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,13 +1,46 @@
|
|
1
1
|
# TimeInterval
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/SebastianEdwards/time-interval)
|
4
|
+
[](https://codeclimate.com/github/SebastianEdwards/time-interval)
|
5
|
+
|
6
|
+
#### Did you know that the ISO8601 defines time interval standards?
|
7
|
+
|
8
|
+
Find out all about it here: http://en.wikipedia.org/wiki/ISO_8601#Time_intervals
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
# A one month period
|
12
|
+
interval = TimeInterval.parse "2007-03-01T00:00:00Z/P1M"
|
13
|
+
interval.start_time # => 2007-03-01 00:00:00 UTC
|
14
|
+
interval.end_time # => 2007-04-01 00:00:00 UTC
|
15
|
+
|
16
|
+
# A period defined by two time points
|
17
|
+
interval = TimeInterval.parse "2007-03-01T00:00:00Z/2007-09-01T00:00:00Z"
|
18
|
+
interval.start_time # => 2007-03-01 00:00:00 UTC
|
19
|
+
interval.end_time # => 2007-09-01 00:00:00 UTC
|
20
|
+
|
21
|
+
# A repeating five minute period
|
22
|
+
repeating_interval = TimeInterval.parse "R/2007-03-01T00:00:00Z/PT5M"
|
23
|
+
periods = repeating_interval.take(100) # => using take due to infinite nature of repeating interval
|
24
|
+
periods.last.start_time # => 2007-03-01 08:15:00 UTC
|
25
|
+
periods.last.end_time # => 2007-03-01 08:20:00 UTC
|
26
|
+
|
27
|
+
# A two week period repeated two times
|
28
|
+
repeating_interval = TimeInterval.parse "R2/2007-03-01T00:00:00Z/P2W"
|
29
|
+
periods = repeating_interval.to_a
|
30
|
+
periods.length # => 2
|
31
|
+
periods[0].start_time # => 2007-03-01 00:00:00 UTC
|
32
|
+
periods[0].end_time # => 2007-03-15 00:00:00 UTC
|
33
|
+
periods[1].start_time # => 2007-03-15 00:00:00 UTC
|
34
|
+
periods[1].end_time # => 2007-03-29 00:00:00 UTC
|
35
|
+
periods[2] # => nil
|
36
|
+
```
|
4
37
|
|
5
38
|
## Installation
|
6
39
|
|
7
40
|
Add this line to your application's Gemfile:
|
8
41
|
|
9
42
|
```ruby
|
10
|
-
gem '
|
43
|
+
gem 'time-interval'
|
11
44
|
```
|
12
45
|
|
13
46
|
And then execute:
|
@@ -16,15 +49,19 @@ And then execute:
|
|
16
49
|
|
17
50
|
Or install it yourself as:
|
18
51
|
|
19
|
-
$ gem install
|
52
|
+
$ gem install time-interval
|
20
53
|
|
21
54
|
## Usage
|
22
55
|
|
23
|
-
|
56
|
+
`TimeInterval.parse(iso8601)` will parse ISO8601 string into a time, interval, or repeating interval.
|
57
|
+
|
58
|
+
`TimeInterval.repeating?(iso8601)` will check if ISO8601 string is a repeating interval.
|
59
|
+
|
60
|
+
`TimeInterval.interval?(iso8601)` will check if ISO8601 string is an interval.
|
24
61
|
|
25
62
|
## Contributing
|
26
63
|
|
27
|
-
1. Fork it ( https://github.com/
|
64
|
+
1. Fork it ( https://github.com/SebastianEdwards/time-interval/fork )
|
28
65
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
66
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
67
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/lib/time_interval.rb
CHANGED
@@ -27,8 +27,11 @@ RSpec.describe TimeInterval do
|
|
27
27
|
context 'iso8601 is not an interval' do
|
28
28
|
let(:iso8601) { '2007-03-01T13:00:00Z' }
|
29
29
|
|
30
|
-
it 'should return a
|
31
|
-
|
30
|
+
it 'should return a TimePair with no duration' do
|
31
|
+
parsed = TimeInterval.parse(iso8601)
|
32
|
+
|
33
|
+
expect(parsed).to be_a TimePair
|
34
|
+
expect(parsed.start_time).to eq parsed.end_time
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time-interval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Edwards
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".travis.yml"
|
92
93
|
- Gemfile
|
93
94
|
- Guardfile
|
94
95
|
- LICENSE.txt
|