diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index a4a6562c74d8947d22bc7004e8a9235b2dcd1697..7c3a5eaace3b0563486d9425faf5c659bd36cf40 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -80,8 +80,11 @@ def to_i private + def offset_in_seconds + (offset * 86400).to_i + end + def seconds_since_unix_epoch - seconds_per_day = 86_400 - (self - ::DateTime.civil(1970)) * seconds_per_day + (jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight end end diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 183d58482db954e39caed3d8301d046432757049..21b7efdc73ac8b55030e82d97bb58f4a7cfbae21 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -427,6 +427,7 @@ def test_to_f def test_to_i assert_equal 946684800, DateTime.civil(2000).to_i + assert_equal 946684800, DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_i end protected