Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an Iso8601TimeRange class to manage ranges in ISO8601 format.
- Loading branch information
Alessandro Morandi
committed
Mar 2, 2012
1 parent
38f0685
commit a81533f
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |