Skip to content

Commit

Permalink
Time.at: Updated for change in result format on 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Jun 5, 2009
1 parent 156a70a commit c31686b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
15 changes: 12 additions & 3 deletions core/time/at_spec.rb
Expand Up @@ -2,11 +2,20 @@
require File.dirname(__FILE__) + '/fixtures/methods'

describe "Time.at" do
it "converts to time object" do
# the #chomp calls are necessary because of RSpec
Time.at(1168475924).inspect.chomp.should == localtime(1168475924).chomp
ruby_version_is ""..."1.9" do
it "converts to time object" do
# the #chomp calls are necessary because of RSpec
Time.at(1168475924).inspect.chomp.should == localtime_18(1168475924).chomp
end
end

ruby_version_is "1.9" do
it "converts to time object" do
# the #chomp calls are necessary because of RSpec
Time.at(1168475924).inspect.chomp.should == localtime_19(1168475924).chomp
end
end

it "creates a new time object with the value given by time" do
t = Time.now
Time.at(t).inspect.should == t.inspect
Expand Down
18 changes: 17 additions & 1 deletion core/time/fixtures/methods.rb
Expand Up @@ -20,7 +20,9 @@ def with_timezone(name, offset = nil, daylight_saving_zone = "")
end
end

def localtime(seconds)
# Returns the given time in the same format as returned by
# Time.at(seconds).inspect on MRI 1.8
def localtime_18(seconds)
platform_is :os => [:darwin, :bsd] do
return `LC_ALL=C date -r #{seconds} +'%a %b %d %H:%M:%S %z %Y'`.chomp
end
Expand All @@ -31,3 +33,17 @@ def localtime(seconds)

return `LC_ALL=C date -j -f "%s" #{seconds} "+%a %b %d %H:%M:%S %z %Y"`.chomp
end

# Returns the given time in the same format as returned by
# Time.at(seconds).inspect on MRI 1.9
def localtime_19(seconds)
platform_is :os => [:darwin, :bsd] do
return `LC_ALL=C date -r #{seconds} +'%F %H:%M:%S %z'`.chomp
end

platform_is :os => :linux do
return `LC_ALL=C date -d @#{seconds} +'%F %H:%M:%S %z'`.chomp
end

return `LC_ALL=C date -j -f "%s" #{seconds} "+%F %H:%M:%S %z"`.chomp
end

0 comments on commit c31686b

Please sign in to comment.