Created
April 7, 2014 20:38
-
-
Save ctweney/10047985 to your computer and use it in GitHub Desktop.
Demonstration of bug in Rails DateTime.to_i function
This file contains hidden or 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
require 'test_helper' | |
class DateTimeBugTest < ActiveSupport::TestCase | |
test "a PDT parsed DateTime should convert to_i and back again" do | |
original_date=DateTime.parse('2014-04-05T23:59:59-07:00') | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
test "a GMT parsed DateTime should convert to_i and back again" do | |
original_date=DateTime.parse('2014-04-05T23:59:59-00:00') | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
test "a constructed PDT DateTime should convert to_i and back again" do | |
original_date = DateTime.new(2014, 4, 5, 23, 59, 59, Rational(-7, 24)) | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
test "a constructed GMT DateTime should convert to_i and back again" do | |
original_date = DateTime.new(2014, 4, 5, 23, 59, 59) | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
test "a constructed PDT DateTime at midnight should convert to_i and back again" do | |
original_date = DateTime.new(2014, 4, 5, 0, 0, 0, Rational(-7, 24)) | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
test "a constructed PDT DateTime at 23:59:00 should convert to_i and back again" do | |
original_date = DateTime.new(2014, 4, 5, 23, 59, 0, Rational(-7, 24)) | |
assert original_date == DateTime.strptime(original_date.to_i.to_s, '%s') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment