timerage 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3acb06877cbd9dfa9823c54c3b8e4fd11270db92
4
- data.tar.gz: ed5a9339c042aacd06fb2cb1edbe937b60dee29c
3
+ metadata.gz: 5d2ce967a8b55c69a7296b30f83b8e4cbf187926
4
+ data.tar.gz: fac80cd77fdacd79a53c76f54c7c15943da8b932
5
5
  SHA512:
6
- metadata.gz: 9d814211ed6c43433c550de50ba581eb85d87bbc29dfcd59acc15199092fcce343b6fb59729306fc33a0ef0593bdd0670774b9d2540d1b6072164a8be74b4db9
7
- data.tar.gz: ae499db68b130aed3f9e640b1f439191a6ed723f15d2332007ae90f1176e1ed483933c0edbad3895652d1b250a51be858d7989c7ac7d59aa38f8a49b11e9d2c1
6
+ metadata.gz: a4eafa5361792a724815d1c90a1c44f7f63b37bfe82ee08015310c98205bb87bbb6d5984802372b8c2adfedd3d5feafc711ea5a9f29437fc8fb4eed692540465
7
+ data.tar.gz: 9049a7ddff2190f712eadea970f727fa0d9ca9fcd4c1e04f65d37d7a82506e56b2b8ef97ee874c4b40e7961466062ab2c89ba27f94483df4e9d878a9107e43f0
@@ -23,7 +23,7 @@ module Timerage
23
23
  end
24
24
  end
25
25
 
26
- # Returns and ISO8601 interval representation of self
26
+ # Returns an ISO8601 interval representation of self
27
27
  # Takes same args as Time#iso8601
28
28
  def iso8601(*args)
29
29
  "#{self.begin.iso8601(*args)}/#{self.end.iso8601(*args)}"
@@ -59,5 +59,21 @@ module Timerage
59
59
  end
60
60
  end
61
61
  end
62
+
63
+ # class methods
64
+ # =============
65
+
66
+ # Returns a new TimeInterval representation of the iso8601 interval
67
+ # represented by the specified string.
68
+ #
69
+ # --
70
+ #
71
+ # Currently this only supports `<begin>/<end>` style time intervals.
72
+ def self.iso8601(str)
73
+ new *str.split("/").map{|s| Time.iso8601(s)}
74
+
75
+ rescue ArgumentError
76
+ raise ArgumentError, "Invalid iso8601 interval: #{str.inspect}"
77
+ end
62
78
  end
63
79
  end
@@ -1,3 +1,3 @@
1
1
  module Timerage
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/timerage.rb CHANGED
@@ -1,8 +1,21 @@
1
1
  require "timerage/version"
2
+ require "time"
2
3
 
3
4
  module Timerage
4
5
  autoload :TimeInterval, "timerage/time_interval"
5
6
 
7
+ # Returns a Time or Timerage::TimeInterval representation of the
8
+ # iso8601 str.
9
+ #
10
+ # --
11
+ #
12
+ # Currently this only supports `<begin>/<end>` style time intervals.
13
+ def self.parse_iso8601(str)
14
+ TimeInterval.iso8601(str)
15
+ rescue ArgumentError
16
+ Time.iso8601(str)
17
+ end
18
+
6
19
  refine Range do
7
20
  def step(n, &blk)
8
21
  if self.begin.kind_of?(Time) || self.begin.kind_of?(Date)
@@ -11,6 +11,14 @@ describe Timerage::TimeInterval do
11
11
  specify { expect(described_class.new(now-1, now, false )).to be_kind_of described_class }
12
12
  end
13
13
 
14
+ describe ".iso8601" do
15
+ specify { expect(described_class
16
+ .iso8601("2001-01-01T00:00:00Z/2001-01-02T00:00:00-06:00"))
17
+ .to be_kind_of described_class }
18
+ specify { expect{described_class.iso8601("2001-01-01T00:00:00Z")}
19
+ .to raise_error ArgumentError }
20
+ end
21
+
14
22
  subject(:interval) { described_class.new(now-duration, now) }
15
23
 
16
24
  it { is_expected.to behave_like_a Range }
@@ -9,11 +9,19 @@ describe Timerage do
9
9
  specify { expect(range.to_time_interval).to be_kind_of Timerage::TimeInterval }
10
10
  specify { expect{|b| range.step(1200, &b) }.to yield_control.at_least(:once) }
11
11
 
12
+ describe ".iso8601" do
13
+ specify { expect(described_class
14
+ .parse_iso8601("2001-01-01T00:00:00Z/2001-01-02T00:00:00-06:00"))
15
+ .to be_kind_of Timerage::TimeInterval }
16
+ specify { expect(described_class.parse_iso8601("2001-01-01T00:00:00Z"))
17
+ .to be_kind_of Time }
18
+ end
19
+
12
20
  context "interval include end" do
13
21
  specify { expect{|b| range.step(1200, &b) }
14
22
  .to yield_successive_args now-duration, now-(duration-1200), now-(duration-2400), now }
15
23
 
16
- end
24
+ end
17
25
 
18
26
  context "interval exclude end" do
19
27
  subject (:range) { Range.new(now-duration, now, true) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timerage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Williams
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-12 00:00:00.000000000 Z
12
+ date: 2015-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler