aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time/conversions.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-05-21 14:57:23 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-05-21 14:57:23 +0000
commit194fc9de5d0d0838e456c9a01cdb14f716fb92d9 (patch)
tree2a01751e575b52431072c9f16a769d7b950d292a /activesupport/lib/active_support/core_ext/time/conversions.rb
parent52ecf9a31896f20125671bb24f4a01171c4ec3b2 (diff)
downloadrails-194fc9de5d0d0838e456c9a01cdb14f716fb92d9.tar.gz
rails-194fc9de5d0d0838e456c9a01cdb14f716fb92d9.tar.bz2
rails-194fc9de5d0d0838e456c9a01cdb14f716fb92d9.zip
Slight change to allow custom date/time conversions #1326 [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1344 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/time/conversions.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb
index 689da6db52..fadfb6b0df 100644
--- a/activesupport/lib/active_support/core_ext/time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -5,6 +5,12 @@ module ActiveSupport #:nodoc:
module Time #:nodoc:
# Getting times in different convenient string representations and other objects
module Conversions
+ DATE_FORMATS = {
+ :db => "%Y-%m-%d %H:%M:%S",
+ :short => "%e %b %H:%M",
+ :long => "%B %e, %Y %H:%M"
+ }
+
def self.append_features(klass)
super
klass.send(:alias_method, :to_default_s, :to_s)
@@ -12,12 +18,7 @@ module ActiveSupport #:nodoc:
end
def to_formatted_s(format = :default)
- case format
- when :default then to_default_s
- when :db then strftime("%Y-%m-%d %H:%M:%S")
- when :short then strftime("%e %b %H:%M").strip
- when :long then strftime("%B %e, %Y %H:%M").strip
- end
+ DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s
end
def to_date