Skip to content

Commit

Permalink
Merge pull request #255 from bogardon/master
Browse files Browse the repository at this point in the history
IS8601 Date Formats
  • Loading branch information
clayallsopp committed Jun 18, 2013
2 parents 7bfbaf1 + 3467439 commit aeaec7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions motion/core/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ def self.iso8601(time)
cached_date_formatter("yyyy-MM-dd'T'HH:mm:ss'Z'").
dateFromString(time)
end

def self.iso8601_with_timezone(time)
cached_date_formatter("yyyy-MM-dd'T'HH:mm:ssZZZZZ").
dateFromString(time)
end

private

Expand Down
18 changes: 14 additions & 4 deletions spec/motion/core/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,49 @@
describe "parsing an iso8601 formatted time to a Time object" do
before do
@time = Time.iso8601("2012-05-31T19:41:33Z")
@time_with_timezone = Time.iso8601_with_timezone("1987-08-10T06:00:00+02:00")
end

it "should be a time" do
@time.instance_of?(Time).should == true
@time_with_timezone.instance_of?(Time).should == true
end

# # Crashes Buggy RubyMotion 1.18
# it "should be converted to the local timezone automatically" do
# @time.zone.should == Time.now.zone
# end
# Crashes Buggy RubyMotion 1.18
it "should be converted to the local timezone automatically" do
local_zone = Time.now.zone
@time.zone.should == local_zone
@time_with_timezone.zone == local_zone
end

it "should have a valid year" do
@time.utc.year.should == 2012
@time_with_timezone.utc.year.should == 1987
end

it "should have a valid month" do
@time.utc.month.should == 5
@time_with_timezone.utc.month.should == 8
end

it "should have a valid day" do
@time.utc.day.should == 31
@time_with_timezone.utc.day.should == 10
end

it "should have a valid hour" do
@time.utc.hour.should == 19
@time_with_timezone.utc.hour.should == 4
end

it "should have a valid minute" do
@time.utc.min.should == 41
@time_with_timezone.utc.min.should == 0
end

it "should have a valid second" do
@time.utc.sec.should == 33
@time_with_timezone.utc.sec.should == 0
end
end

Expand Down

0 comments on commit aeaec7d

Please sign in to comment.