Skip to content

Commit

Permalink
Added an Iso8601TimeRange class to manage ranges in ISO8601 format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Morandi committed Mar 2, 2012
1 parent 38f0685 commit a81533f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/iso8601_time_range.rb
@@ -0,0 +1,18 @@
class Iso8601TimeRange
def initialize(time_range)
raise ArgumentError.new("A TimeRange argument is needed") unless time_range.is_a?(TimeRange)
@time_range = time_range
end

def start
@time_range.start.utc.iso8601
end

def finish
@time_range.finish.utc.iso8601
end

def to_s
"#{start}~#{finish}"
end
end
19 changes: 19 additions & 0 deletions spec/lib/iso8601_time_range_spec.rb
@@ -0,0 +1,19 @@
require 'spec_helper'

describe Iso8601TimeRange do
context "when not initialized with a TimeRange" do
it "should raise error" do
expect{
Iso8601TimeRange.new([1, 2])
}.to raise_error ArgumentError
end
end

context "when initialized with a TimeRange" do
let(:time_range) { TimeRange.today }
subject { Iso8601TimeRange.new(time_range) }

it { subject.start.should == time_range.start.utc.iso8601 }
it { subject.finish.should == time_range.finish.utc.iso8601 }
end
end

0 comments on commit a81533f

Please sign in to comment.