date in content types compatible with ruby 1.9.2

This commit is contained in:
dinedine 2011-01-11 00:50:42 +01:00
parent 933c26dbb2
commit ff01539bb5
3 changed files with 12 additions and 10 deletions

View File

@ -42,7 +42,7 @@ GEM
arel (2.0.6)
autotest (4.4.6)
ZenTest (>= 4.4.1)
bcrypt-ruby (2.1.3)
bcrypt-ruby (2.1.4)
bson (1.1.5)
bson_ext (1.1.5)
builder (2.1.2)
@ -55,7 +55,7 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.27)
xpath (~> 0.1.2)
celerity (0.8.6)
celerity (0.8.7)
childprocess (0.1.6)
ffi (~> 0.6.3)
closure-compiler (0.3.3)
@ -89,7 +89,7 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
excon (0.3.7)
excon (0.3.8)
factory_girl (1.3.2)
factory_girl_rails (1.0.1)
factory_girl (~> 1.3)
@ -244,7 +244,7 @@ GEM
warden (0.10.7)
rack (>= 1.0.0)
will_paginate (3.0.pre2)
xpath (0.1.2)
xpath (0.1.3)
nokogiri (~> 1.3)
yard (0.6.4)
yui-compressor (0.9.1)

View File

@ -73,6 +73,7 @@ module Locomotive
value = (case field.kind.downcase
when 'file' then self.open_sample_asset(value)
when 'boolean' then Boolean.set(value)
when 'date' then Date.parse(value)
else
value
end)

View File

@ -4,16 +4,17 @@ module Locomotive
module Date
def localized_date(input, *args)
format, locale = args[0], args[1] rescue 'en'
format, locale = args[0], args[1] || 'en'
date = input.is_a?(String) ? Time.parse(input) : input
return input.to_s if format.to_s.empty?
if format.to_s.empty?
return input.to_s
if input.is_a?(String)
fragments = ::Date._strptime(input, I18n.t('date.formats.default'))
date = ::Date.new(fragments[:year], fragments[:mon], fragments[:mday])
else
date = input
end
date = input.is_a?(String) ? Time.parse(input) : input
if date.respond_to?(:strftime)
I18n.locale = locale
I18n.l date, :format => format