ruby-cldr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/README.textile +9 -6
- data/VERSION +1 -1
- data/lib/cldr.rb +1 -1
- data/lib/cldr/data.rb +9 -29
- data/lib/cldr/download.rb +2 -2
- data/lib/cldr/export.rb +8 -2
- data/lib/cldr/export/code.rb +34 -0
- data/lib/cldr/export/code/numbers.rb +29 -0
- data/lib/cldr/export/data.rb +36 -0
- data/lib/cldr/export/data/base.rb +61 -0
- data/lib/cldr/export/data/calendars.rb +14 -0
- data/lib/cldr/export/data/calendars/gregorian.rb +142 -0
- data/lib/cldr/export/data/currencies.rb +28 -0
- data/lib/cldr/export/data/delimiters.rb +29 -0
- data/lib/cldr/export/data/languages.rb +19 -0
- data/lib/cldr/export/data/numbers.rb +67 -0
- data/lib/cldr/export/data/plurals.rb +41 -0
- data/lib/cldr/{data → export/data}/plurals/cldr_grammar.treetop +0 -0
- data/lib/cldr/export/data/plurals/grammar.rb +538 -0
- data/lib/cldr/export/data/plurals/rules.rb +119 -0
- data/lib/cldr/export/data/territories.rb +19 -0
- data/lib/cldr/export/data/timezones.rb +27 -0
- data/lib/cldr/export/data/units.rb +29 -0
- data/lib/cldr/export/ruby.rb +1 -1
- data/lib/cldr/export/yaml.rb +1 -1
- data/lib/cldr/format.rb +1 -97
- data/lib/cldr/format/currency.rb +1 -1
- data/lib/cldr/format/date.rb +1 -1
- data/lib/cldr/format/datetime.rb +14 -18
- data/lib/cldr/format/datetime/base.rb +1 -1
- data/lib/cldr/format/decimal.rb +1 -1
- data/lib/cldr/format/decimal/base.rb +1 -1
- data/lib/cldr/format/decimal/fraction.rb +1 -1
- data/lib/cldr/format/decimal/integer.rb +1 -1
- data/lib/cldr/format/decimal/number.rb +1 -1
- data/lib/cldr/format/percent.rb +1 -1
- data/lib/cldr/format/time.rb +1 -1
- data/lib/cldr/thor.rb +3 -3
- data/test/all.rb +1 -1
- data/test/export/code/numbers_test.rb +11 -0
- data/test/{data → export/data}/all.rb +1 -1
- data/test/{data → export/data}/calendars_test.rb +18 -18
- data/test/{data → export/data}/currencies_test.rb +6 -6
- data/test/{data → export/data}/delimiters_test.rb +6 -6
- data/test/{data → export/data}/languages_test.rb +6 -6
- data/test/{data → export/data}/numbers_test.rb +8 -8
- data/test/export/data/plurals_test.rb +141 -0
- data/test/{data → export/data}/territories_test.rb +6 -6
- data/test/{data → export/data}/timezones_test.rb +6 -6
- data/test/{data → export/data}/units_test.rb +6 -6
- data/test/export_test.rb +8 -8
- data/test/{formats → format}/all.rb +1 -1
- data/test/format/currency_test.rb +0 -0
- data/test/format/date_test.rb +265 -0
- data/test/format/datetime_test.rb +18 -0
- data/test/{formats → format}/decimal/fraction_test.rb +4 -4
- data/test/{formats → format}/decimal/integer_test.rb +17 -17
- data/test/{formats → format}/decimal/number_test.rb +19 -19
- data/test/{formats → format}/decimal_test.rb +5 -5
- data/test/format/percent_test.rb +0 -0
- data/test/format/time_test.rb +195 -0
- data/test/test_autotest.rb +36 -0
- data/test/test_helper.rb +16 -1
- metadata +124 -114
- data/lib/cldr/data/base.rb +0 -66
- data/lib/cldr/data/calendars.rb +0 -12
- data/lib/cldr/data/calendars/gregorian.rb +0 -124
- data/lib/cldr/data/currencies.rb +0 -26
- data/lib/cldr/data/delimiters.rb +0 -21
- data/lib/cldr/data/languages.rb +0 -17
- data/lib/cldr/data/numbers.rb +0 -60
- data/lib/cldr/data/plurals.rb +0 -39
- data/lib/cldr/data/plurals/grammar.rb +0 -536
- data/lib/cldr/data/plurals/rules.rb +0 -113
- data/lib/cldr/data/territories.rb +0 -17
- data/lib/cldr/data/timezones.rb +0 -25
- data/lib/cldr/data/units.rb +0 -25
- data/test/data/plurals_test.rb +0 -132
- data/test/formats/datetime/all.rb +0 -3
- data/test/formats/datetime/date_test.rb +0 -31
- data/test/formats/datetime/datetime_test.rb +0 -18
- data/test/formats/datetime/day_test.rb +0 -41
- data/test/formats/datetime/hour_test.rb +0 -79
- data/test/formats/datetime/minute_test.rb +0 -25
- data/test/formats/datetime/month_test.rb +0 -76
- data/test/formats/datetime/period_test.rb +0 -20
- data/test/formats/datetime/quarter_test.rb +0 -118
- data/test/formats/datetime/second_test.rb +0 -80
- data/test/formats/datetime/time_test.rb +0 -33
- data/test/formats/datetime/timezone_test.rb +0 -23
- data/test/formats/datetime/year_test.rb +0 -57
- data/test/formats/format_test.rb +0 -66
- data/test/formats/rails_compat/all.rb +0 -3
- data/test/formats/rails_compat/format_integer_test.rb +0 -56
- data/test/formats/rails_compat/format_number_test.rb +0 -134
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rexml/document'
|
3
|
-
|
4
|
-
class Cldr
|
5
|
-
module Data
|
6
|
-
class Plurals
|
7
|
-
class Rules < Array
|
8
|
-
class << self
|
9
|
-
def parse(xml)
|
10
|
-
rules = new
|
11
|
-
REXML::Document.new(xml).elements.each('//pluralRules') do |tag|
|
12
|
-
rule = Rule.new(tag.attributes['locales'].split(/\s+/))
|
13
|
-
tag.elements.each('pluralRule') { |tag| rule << [tag.attributes['count'], tag.text] }
|
14
|
-
rules << rule
|
15
|
-
end
|
16
|
-
rules
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def locales
|
21
|
-
@locales ||= map { |rule| rule.locales }.flatten.map(&:to_s).sort.map(&:to_sym)
|
22
|
-
end
|
23
|
-
|
24
|
-
def rule(locale)
|
25
|
-
detect { |rule| rule.locales.include?(locale.to_sym) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_ruby(options = {})
|
29
|
-
namespaces = options[:namespaces] || [:i18n]
|
30
|
-
code = locales.map do |locale|
|
31
|
-
rule = self.rule(locale)
|
32
|
-
ruby = "{ :plural => { :keys => #{rule.keys.inspect}, :rule => #{rule.to_ruby} } }"
|
33
|
-
ruby = namespaces.reverse.inject(ruby) { |ruby, namespace| "{ #{namespace.inspect} => #{ruby} }"}
|
34
|
-
"#{locale.inspect} => #{ruby}"
|
35
|
-
end.join(",\n")
|
36
|
-
code = code.split("\n").map { |line| " #{line}" }.join("\n")
|
37
|
-
"{\n" + code + "\n}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Rule < Array
|
42
|
-
class << self
|
43
|
-
def parse(code)
|
44
|
-
case code
|
45
|
-
when /and/
|
46
|
-
code.split(/and/).inject(Proposition.new('&&')) { |rule, code| rule << parse(code) }
|
47
|
-
when /or/
|
48
|
-
code.split(/or/).inject(Proposition.new('||')) { |rule, code| rule << parse(code) }
|
49
|
-
when /n( mod ([\d]+))? is (not )?([\d]+)/
|
50
|
-
Expression.new(:is, $2, !!$3, $4)
|
51
|
-
when /n( mod ([\d]+))?( not)? in ([\d]+\.\.[\d]+)/
|
52
|
-
Expression.new(:in, $2, !!$3, eval($4).to_a.inspect)
|
53
|
-
when /n/
|
54
|
-
Expression.new
|
55
|
-
else
|
56
|
-
raise "can not parse #{code}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
attr_reader :locales
|
62
|
-
|
63
|
-
def initialize(locales)
|
64
|
-
@locales = locales.map { |locale| locale.gsub('_', '-').to_sym }
|
65
|
-
end
|
66
|
-
|
67
|
-
def keys
|
68
|
-
inject([]) { |keys, (key, code)| keys << key.to_sym } << :other
|
69
|
-
end
|
70
|
-
|
71
|
-
def to_ruby
|
72
|
-
@condition ||= 'lambda { |n| ' + reverse.inject(':other') do |result, (key, code)|
|
73
|
-
code = self.class.parse(code).to_ruby
|
74
|
-
"#{code} ? :#{key} : #{result}"
|
75
|
-
end + ' }'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class Proposition < Array
|
80
|
-
def initialize(type = nil)
|
81
|
-
@type = type
|
82
|
-
end
|
83
|
-
|
84
|
-
def to_ruby
|
85
|
-
@ruby ||= map { |expr| expr.to_ruby }.join(" #{@type} ")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
class Expression
|
90
|
-
attr_reader :operator, :operand, :mod, :negate
|
91
|
-
|
92
|
-
def initialize(operator = nil, mod = nil, negate = nil, operand = nil)
|
93
|
-
@operator, @mod, @negate, @operand = operator, mod, negate, operand
|
94
|
-
end
|
95
|
-
|
96
|
-
def to_ruby
|
97
|
-
@ruby ||= begin
|
98
|
-
op = 'n'
|
99
|
-
op << " % #{@mod}" if mod
|
100
|
-
case @operator
|
101
|
-
when :is
|
102
|
-
op + (@negate ? ' != ' : ' == ') + @operand
|
103
|
-
when :in
|
104
|
-
(@negate ? '!' : '') + "#{@operand}.include?(#{op})"
|
105
|
-
else
|
106
|
-
op
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Territories < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:territories] = territories
|
7
|
-
end
|
8
|
-
|
9
|
-
def territories
|
10
|
-
@territories ||= select('localeDisplayNames/territories/territory').inject({}) do |result, node|
|
11
|
-
result[node.attribute('type').value.to_sym] = node.content unless draft?(node)
|
12
|
-
result
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/cldr/data/timezones.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# I probably don't really get timezones.
|
2
|
-
|
3
|
-
class Cldr
|
4
|
-
module Data
|
5
|
-
class Timezones < Base
|
6
|
-
def initialize(locale)
|
7
|
-
super
|
8
|
-
self[:timezones] = timezones
|
9
|
-
end
|
10
|
-
|
11
|
-
def timezones
|
12
|
-
@timezones ||= select('dates/timeZoneNames/zone').inject({}) do |result, zone|
|
13
|
-
type = zone.attribute('type').value.to_sym
|
14
|
-
city = select(zone, 'exemplarCity').first
|
15
|
-
result[type] = {}
|
16
|
-
# see en.xml, Europe/London, does not have an exemplarCity element
|
17
|
-
# instead it has long and short daylight names which otherwise only
|
18
|
-
# have metazones. (??)
|
19
|
-
result[type][:city] = city.content if city
|
20
|
-
result
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/cldr/data/units.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
class Cldr
|
2
|
-
module Data
|
3
|
-
class Units < Base
|
4
|
-
def initialize(locale)
|
5
|
-
super
|
6
|
-
self[:units] = units
|
7
|
-
end
|
8
|
-
|
9
|
-
def units
|
10
|
-
select('units/unit').inject({}) do |result, node|
|
11
|
-
result[node.attribute('type').value.to_sym] = unit(node)
|
12
|
-
result
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def unit(node)
|
17
|
-
node.xpath('unitPattern').inject({}) do |result, node|
|
18
|
-
count = node.attribute('count') ? node.attribute('count').value.to_sym : :one
|
19
|
-
result[count] = node.content unless draft?(node)
|
20
|
-
result
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/test/data/plurals_test.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
-
|
3
|
-
class TestCldrDataPluralParser < Test::Unit::TestCase
|
4
|
-
def cldr_data
|
5
|
-
File.read(File.dirname(__FILE__) + '/../../vendor/cldr/common/supplemental/plurals.xml')
|
6
|
-
end
|
7
|
-
|
8
|
-
def cldr_rules
|
9
|
-
Cldr::Data::Plurals::Rules.parse(cldr_data)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_compiles_to_valid_ruby_code
|
13
|
-
assert_nothing_raised { eval(cldr_rules.to_ruby) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_evals_to_a_hash_containing_plural_rule_and_keys_per_locale
|
17
|
-
data = eval(cldr_rules.to_ruby)
|
18
|
-
assert Hash === data
|
19
|
-
assert Proc === data[:de][:i18n][:plural][:rule]
|
20
|
-
assert_equal [:one, :other], data[:de][:i18n][:plural][:keys]
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_lookup_rule_by_locale
|
24
|
-
assert_equal "lambda { |n| n == 1 ? :one : :other }", cldr_rules.rule(:de).to_ruby
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_parses_n
|
28
|
-
assert Cldr::Data::Plurals::Rule.parse('n').is_a?(Cldr::Data::Plurals::Expression)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_parses_n_is_1
|
32
|
-
rule = Cldr::Data::Plurals::Rule.parse('n is 1')
|
33
|
-
assert_equal [:is, '1'], [rule.operator, rule.operand]
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_parses_n_mod_1_is_1
|
37
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 is 1')
|
38
|
-
assert_equal [:is, '1', '1'], [rule.operator, rule.operand, rule.mod]
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_parses_n_is_not_1
|
42
|
-
rule = Cldr::Data::Plurals::Rule.parse('n is not 1')
|
43
|
-
assert_equal [:is, '1', true], [rule.operator, rule.operand, rule.negate]
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_parses_n_mod_1_is_not_1
|
47
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 is not 1')
|
48
|
-
assert_equal [:is, '1', true, '1'], [rule.operator, rule.operand, rule.negate, rule.mod]
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_parses_n_in_1_2
|
52
|
-
rule = Cldr::Data::Plurals::Rule.parse('n in 1..2')
|
53
|
-
assert_equal [:in, '[1, 2]'], [rule.operator, rule.operand]
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_parses_n_mod_1_in_1_2
|
57
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 in 1..2')
|
58
|
-
assert_equal [:in, '[1, 2]', '1'], [rule.operator, rule.operand, rule.mod]
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_parses_n_not_in_1_2
|
62
|
-
rule = Cldr::Data::Plurals::Rule.parse('n not in 1..2')
|
63
|
-
assert_equal [:in, '[1, 2]', true], [rule.operator, rule.operand, rule.negate]
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_parses_n_mod_1_not_in_1_2
|
67
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 not in 1..2')
|
68
|
-
assert_equal [:in, '[1, 2]', true, '1'], [rule.operator, rule.operand, rule.negate, rule.mod]
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_parses_or_condition
|
72
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 is not 2 or n mod 2 in 3..4')
|
73
|
-
assert_equal 2, rule.size
|
74
|
-
assert_equal [:is, '2', true, '1'], [rule[0].operator, rule[0].operand, rule[0].negate, rule[0].mod]
|
75
|
-
assert_equal [:in, '[3, 4]', false, '2'], [rule[1].operator, rule[1].operand, rule[1].negate, rule[1].mod]
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_parses_and_condition
|
79
|
-
rule = Cldr::Data::Plurals::Rule.parse('n mod 1 is not 2 and n mod 2 in 3..4')
|
80
|
-
assert_equal 2, rule.size
|
81
|
-
assert_equal [:is, '2', true, '1'], [rule[0].operator, rule[0].operand, rule[0].negate, rule[0].mod]
|
82
|
-
assert_equal [:in, '[3, 4]', false, '2'], [rule[1].operator, rule[1].operand, rule[1].negate, rule[1].mod]
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_compiles_n
|
86
|
-
assert_equal 'n', Cldr::Data::Plurals::Rule.parse('n').to_ruby
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_compiles_n_is_2
|
90
|
-
assert_equal 'n == 2', Cldr::Data::Plurals::Rule.parse('n is 2').to_ruby
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_compiles_n_mod_1_is_2
|
94
|
-
assert_equal 'n % 1 == 2', Cldr::Data::Plurals::Rule.parse('n mod 1 is 2').to_ruby
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_compiles_n_is_not_2
|
98
|
-
assert_equal 'n != 2', Cldr::Data::Plurals::Rule.parse('n is not 2').to_ruby
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_compiles_n_mod_1_is_not_2
|
102
|
-
assert_equal 'n % 1 != 2', Cldr::Data::Plurals::Rule.parse('n mod 1 is not 2').to_ruby
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_compiles_n_in_1_2
|
106
|
-
assert_equal '[1, 2].include?(n)', Cldr::Data::Plurals::Rule.parse('n in 1..2').to_ruby
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_compiles_n_mod_1_in_1_2
|
110
|
-
assert_equal '[1, 2].include?(n % 1)', Cldr::Data::Plurals::Rule.parse('n mod 1 in 1..2').to_ruby
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_compiles_n_not_in_1_2
|
114
|
-
assert_equal '![1, 2].include?(n)', Cldr::Data::Plurals::Rule.parse('n not in 1..2').to_ruby
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_compiles_n_mod_1_not_in_1_2
|
118
|
-
assert_equal '![1, 2].include?(n % 1)', Cldr::Data::Plurals::Rule.parse('n mod 1 not in 1..2').to_ruby
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_compiles_or_condition
|
122
|
-
assert_equal 'n % 1 != 2 || [3, 4].include?(n % 2)', Cldr::Data::Plurals::Rule.parse('n mod 1 is not 2 or n mod 2 in 3..4').to_ruby
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_compiles_and_condition
|
126
|
-
assert_equal 'n % 1 != 2 && [3, 4].include?(n % 2)', Cldr::Data::Plurals::Rule.parse('n mod 1 is not 2 and n mod 2 in 3..4').to_ruby
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_compiles_n_mod_100_in_3_99
|
130
|
-
assert_equal '[3, 4, 5, 6].include?(n % 100)', Cldr::Data::Plurals::Rule.parse('n mod 100 in 3..6').to_ruby
|
131
|
-
end
|
132
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
class TestCldrDateFormat < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@locale = :de
|
9
|
-
@calendar = Cldr::Data::Calendars.new(@locale)[:calendars][:gregorian]
|
10
|
-
end
|
11
|
-
|
12
|
-
def format(object, pattern)
|
13
|
-
Cldr::Format::Date.new(pattern, @calendar).apply(object)
|
14
|
-
end
|
15
|
-
|
16
|
-
define_method "test: full date pattern :de" do
|
17
|
-
assert_equal 'Montag, 11. Januar 2010', format(Date.new(2010, 1, 11), 'EEEE, d. MMMM y')
|
18
|
-
end
|
19
|
-
|
20
|
-
define_method "test: long date pattern :de" do
|
21
|
-
assert_equal '11. Januar 2010', format(Date.new(2010, 1, 11), 'd. MMMM y')
|
22
|
-
end
|
23
|
-
|
24
|
-
define_method "test: medium date pattern :de" do
|
25
|
-
assert_equal '11.01.2010', format(Date.new(2010, 1, 11), 'dd.MM.yyyy')
|
26
|
-
end
|
27
|
-
|
28
|
-
define_method "test: short date pattern :de" do
|
29
|
-
assert_equal '11.01.10', format(Date.new(2010, 1, 11), 'dd.MM.yy')
|
30
|
-
end
|
31
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
class TestCldrDatetimeFormat < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@locale = :de
|
9
|
-
@calendar = Cldr::Data::Calendars.new(@locale)[:calendars][:gregorian]
|
10
|
-
end
|
11
|
-
|
12
|
-
define_method "test: datetime pattern :de" do
|
13
|
-
date = Cldr::Format::Date.new('dd.MM.yyyy', @calendar)
|
14
|
-
time = Cldr::Format::Time.new('HH:mm', @calendar)
|
15
|
-
result = Cldr::Format::Datetime.new('{1} {0}', date, time).apply(DateTime.new(2010, 1, 10, 13, 12, 11))
|
16
|
-
assert_equal '10.01.2010 13:12', result
|
17
|
-
end
|
18
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
class TestCldrDateDayFormat < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@locale = :de
|
9
|
-
@calendar = Cldr::Data::Calendars.new(@locale)[:calendars][:gregorian]
|
10
|
-
end
|
11
|
-
|
12
|
-
def format(object, pattern)
|
13
|
-
Cldr::Format::Date.new(pattern, @calendar).apply(object)
|
14
|
-
end
|
15
|
-
|
16
|
-
# DAY
|
17
|
-
|
18
|
-
define_method "test: pattern d" do
|
19
|
-
assert_equal '1', format(Date.new(2010, 1, 1), 'd')
|
20
|
-
assert_equal '10', format(Date.new(2010, 1, 10), 'd')
|
21
|
-
end
|
22
|
-
|
23
|
-
define_method "test: pattern dd" do
|
24
|
-
assert_equal '01', format(Date.new(2010, 1, 1), 'dd')
|
25
|
-
assert_equal '10', format(Date.new(2010, 1, 10), 'dd')
|
26
|
-
end
|
27
|
-
|
28
|
-
define_method "test: pattern E, EE, EEE" do
|
29
|
-
assert_equal 'Fr.', format(Date.new(2010, 1, 1), 'E')
|
30
|
-
assert_equal 'Fr.', format(Date.new(2010, 1, 1), 'EE')
|
31
|
-
assert_equal 'Fr.', format(Date.new(2010, 1, 1), 'EEE')
|
32
|
-
end
|
33
|
-
|
34
|
-
define_method "test: pattern EEEE" do
|
35
|
-
assert_equal 'Freitag', format(Date.new(2010, 1, 1), 'EEEE')
|
36
|
-
end
|
37
|
-
|
38
|
-
define_method "test: pattern EEEEE" do
|
39
|
-
assert_equal 'F', format(Date.new(2010, 1, 1), 'EEEEE')
|
40
|
-
end
|
41
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
class TestCldrDateHourFormat < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@locale = :de
|
9
|
-
@calendar = Cldr::Data::Calendars.new(@locale)[:calendars][:gregorian]
|
10
|
-
end
|
11
|
-
|
12
|
-
def format(object, pattern)
|
13
|
-
Cldr::Format::Time.new(pattern, @calendar).apply(object)
|
14
|
-
end
|
15
|
-
|
16
|
-
define_method "test: h" do
|
17
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 0, 1, 1), 'h')
|
18
|
-
assert_equal '1', format(Time.local(2000, 1, 1, 1, 1, 1), 'h')
|
19
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'h')
|
20
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'h')
|
21
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 23, 1, 1), 'h')
|
22
|
-
end
|
23
|
-
|
24
|
-
define_method "test: hh" do
|
25
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 0, 1, 1), 'hh')
|
26
|
-
assert_equal '01', format(Time.local(2000, 1, 1, 1, 1, 1), 'hh')
|
27
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'hh')
|
28
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'hh')
|
29
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 23, 1, 1), 'hh')
|
30
|
-
end
|
31
|
-
|
32
|
-
define_method "test: H" do
|
33
|
-
assert_equal '0', format(Time.local(2000, 1, 1, 0, 1, 1), 'H')
|
34
|
-
assert_equal '1', format(Time.local(2000, 1, 1, 1, 1, 1), 'H')
|
35
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'H')
|
36
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'H')
|
37
|
-
assert_equal '23', format(Time.local(2000, 1, 1, 23, 1, 1), 'H')
|
38
|
-
end
|
39
|
-
|
40
|
-
define_method "test: HH" do
|
41
|
-
assert_equal '00', format(Time.local(2000, 1, 1, 0, 1, 1), 'HH')
|
42
|
-
assert_equal '01', format(Time.local(2000, 1, 1, 1, 1, 1), 'HH')
|
43
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'HH')
|
44
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'HH')
|
45
|
-
assert_equal '23', format(Time.local(2000, 1, 1, 23, 1, 1), 'HH')
|
46
|
-
end
|
47
|
-
|
48
|
-
define_method "test: K" do
|
49
|
-
assert_equal '0', format(Time.local(2000, 1, 1, 0, 1, 1), 'K')
|
50
|
-
assert_equal '1', format(Time.local(2000, 1, 1, 1, 1, 1), 'K')
|
51
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'K')
|
52
|
-
assert_equal '0', format(Time.local(2000, 1, 1, 12, 1, 1), 'K')
|
53
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 23, 1, 1), 'K')
|
54
|
-
end
|
55
|
-
|
56
|
-
define_method "test: KK" do
|
57
|
-
assert_equal '00', format(Time.local(2000, 1, 1, 0, 1, 1), 'KK')
|
58
|
-
assert_equal '01', format(Time.local(2000, 1, 1, 1, 1, 1), 'KK')
|
59
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'KK')
|
60
|
-
assert_equal '00', format(Time.local(2000, 1, 1, 12, 1, 1), 'KK')
|
61
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 23, 1, 1), 'KK')
|
62
|
-
end
|
63
|
-
|
64
|
-
define_method "test: k" do
|
65
|
-
assert_equal '24', format(Time.local(2000, 1, 1, 0, 1, 1), 'k')
|
66
|
-
assert_equal '1', format(Time.local(2000, 1, 1, 1, 1, 1), 'k')
|
67
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'k')
|
68
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'k')
|
69
|
-
assert_equal '23', format(Time.local(2000, 1, 1, 23, 1, 1), 'k')
|
70
|
-
end
|
71
|
-
|
72
|
-
define_method "test: kk" do
|
73
|
-
assert_equal '24', format(Time.local(2000, 1, 1, 0, 1, 1), 'kk')
|
74
|
-
assert_equal '01', format(Time.local(2000, 1, 1, 1, 1, 1), 'kk')
|
75
|
-
assert_equal '11', format(Time.local(2000, 1, 1, 11, 1, 1), 'kk')
|
76
|
-
assert_equal '12', format(Time.local(2000, 1, 1, 12, 1, 1), 'kk')
|
77
|
-
assert_equal '23', format(Time.local(2000, 1, 1, 23, 1, 1), 'kk')
|
78
|
-
end
|
79
|
-
end
|