From 79425027302da76a37241f241adbc3aec2e1f2b3 Mon Sep 17 00:00:00 2001 From: Aditya Sanghi Date: Tue, 12 Oct 2010 13:29:38 +0530 Subject: [PATCH] add :time_with_seconds as a Time format to give seconds some love. fixed related documentation --- .../active_support/core_ext/time/conversions.rb | 12 +++++++----- activesupport/test/core_ext/time_ext_test.rb | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index d4ae313..49bd3e4 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -4,11 +4,12 @@ require 'active_support/values/time_zone' class Time DATE_FORMATS = { - :db => "%Y-%m-%d %H:%M:%S", - :number => "%Y%m%d%H%M%S", - :time => "%H:%M", - :short => "%d %b %H:%M", - :long => "%B %d, %Y %H:%M", + :db => "%Y-%m-%d %H:%M:%S", + :number => "%Y%m%d%H%M%S", + :time => "%H:%M", + :time_with_seconds => "%H:%M:%S", + :short => "%d %b %H:%M", + :long => "%B %d, %Y %H:%M", :long_ordinal => lambda { |time| time.strftime("%B #{ActiveSupport::Inflector.ordinalize(time.day)}, %Y %H:%M") }, :rfc822 => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") } } @@ -21,6 +22,7 @@ class Time # # time.to_formatted_s(:time) # => "06:10" # time.to_s(:time) # => "06:10" + # time.to_s(:time_with_seconds) # => "06:10:17" # # time.to_formatted_s(:db) # => "2007-01-18 06:10:17" # time.to_formatted_s(:number) # => "20070118061017" diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 53d4970..e5a8aa5 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -516,6 +516,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase assert_equal "2005-02-21 17:44:30", time.to_s(:db) assert_equal "21 Feb 17:44", time.to_s(:short) assert_equal "17:44", time.to_s(:time) + assert_equal "17:44:30", time.to_s(:time_with_seconds) assert_equal "February 21, 2005 17:44", time.to_s(:long) assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal) with_env_tz "UTC" do -- 1.7.1