From 2ae8300489aaaaaa65f50f3557090b265a2dcc6a Mon Sep 17 00:00:00 2001 From: Serguei Filimonov Date: Fri, 11 Dec 2009 13:08:00 -0800 Subject: Added #to_i to DateTime in ActiveSupport so #to_yaml works correctly on ActiveRecord models with DateTime attributes. --- .../lib/active_support/core_ext/date_time/conversions.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') 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 5f01bc4fd6..47a31839a6 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -78,7 +78,18 @@ class DateTime # Converts self to a floating-point number of seconds since the Unix epoch def to_f - days_since_unix_epoch = self - ::DateTime.civil(1970) - (days_since_unix_epoch * 86_400).to_f + seconds_since_unix_epoch.to_f + end + + # Converts self to an integer number of seconds since the Unix epoch + def to_i + seconds_since_unix_epoch.to_i + end + + private + + def seconds_since_unix_epoch + seconds_per_day = 86_400 + (self - ::DateTime.civil(1970)) * seconds_per_day end end -- cgit v1.2.3