1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed Date and Time localization for ActiveSupport

This commit is contained in:
Luca Guidi 2008-07-02 17:51:34 +02:00
parent 6982acb079
commit 7403c825a0
3 changed files with 96 additions and 21 deletions

View file

@ -1,25 +1,4 @@
I18n.backend.store_translations :'en-US', {
:date => {
:formats => {
:default => "%Y-%m-%d",
:short => "%b %d",
:long => "%B %d, %Y",
},
:day_names => Date::DAYNAMES,
:abbr_day_names => Date::ABBR_DAYNAMES,
:month_names => Date::MONTHNAMES,
:abbr_month_names => Date::ABBR_MONTHNAMES,
:order => [:year, :month, :day]
},
:time => {
:formats => {
:default => "%a, %d %b %Y %H:%M:%S %z",
:short => "%d %b %H:%M",
:long => "%B %d, %Y %H:%M",
},
:am => 'am',
:pm => 'pm'
},
:datetime => {
:distance_in_words => {
:half_a_minute => 'half a minute',

View file

@ -3,5 +3,26 @@ I18n.backend.store_translations :'en-US', {
:array => {
:sentence_connector => 'and'
}
},
:date => {
:formats => {
:default => "%Y-%m-%d",
:short => "%b %d",
:long => "%B %d, %Y",
},
:day_names => Date::DAYNAMES,
:abbr_day_names => Date::ABBR_DAYNAMES,
:month_names => Date::MONTHNAMES,
:abbr_month_names => Date::ABBR_MONTHNAMES,
:order => [:year, :month, :day]
},
:time => {
:formats => {
:default => "%a, %d %b %Y %H:%M:%S %z",
:short => "%d %b %H:%M",
:long => "%B %d, %Y %H:%M",
},
:am => 'am',
:pm => 'pm'
}
}

View file

@ -0,0 +1,75 @@
require 'abstract_unit'
class I18nTest < Test::Unit::TestCase
def setup
@date = Date.parse("2008-7-2")
@time = Time.utc(2008, 7, 2, 16, 47, 1)
end
uses_mocha 'I18nTimeZoneTest' do
def test_time_zone_localization_with_default_format
Time.zone.stubs(:now).returns Time.local(2000)
assert_equal "Sat, 01 Jan 2000 00:00:00 +0100", Time.zone.now.l
end
end
def test_date_localization_should_use_default_format
assert_equal "2008-07-02", @date.l
end
def test_date_localization_with_default_format
assert_equal "2008-07-02", @date.l(nil, :default)
end
def test_date_localization_with_short_format
assert_equal "Jul 02", @date.l(nil, :short)
end
def test_date_localization_with_long_format
assert_equal "July 02, 2008", @date.l(nil, :long)
end
def test_time_localization_should_use_default_format
assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", @time.l
end
def test_time_localization_with_default_format
assert_equal "Wed, 02 Jul 2008 16:47:01 +0100", @time.l(nil, :default)
end
def test_time_localization_with_short_format
assert_equal "02 Jul 16:47", @time.l(nil, :short)
end
def test_time_localization_with_long_format
assert_equal "July 02, 2008 16:47", @time.l(nil, :long)
end
def test_day_names
assert_equal Date::DAYNAMES, :'date.day_names'.t
end
def test_abbr_day_names
assert_equal Date::ABBR_DAYNAMES, :'date.abbr_day_names'.t
end
def test_month_names
assert_equal Date::MONTHNAMES, :'date.month_names'.t
end
def test_abbr_month_names
assert_equal Date::ABBR_MONTHNAMES, :'date.abbr_month_names'.t
end
def test_date_order
assert_equal [:year, :month, :day], :'date.order'.t
end
def test_time_am
assert_equal 'am', :'time.am'.t
end
def test_time_pm
assert_equal 'pm', :'time.pm'.t
end
end