twitter_cldr 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/History.txt +6 -0
  2. data/README.md +61 -5
  3. data/Rakefile +64 -60
  4. data/js/lib/twitter_cldr_js.rb +0 -2
  5. data/lib/twitter_cldr/core_ext.rb +12 -12
  6. data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +13 -11
  7. data/lib/twitter_cldr/localized/localized_array.rb +33 -0
  8. data/lib/twitter_cldr/localized/localized_date.rb +23 -0
  9. data/lib/twitter_cldr/localized/localized_datetime.rb +63 -0
  10. data/lib/twitter_cldr/localized/localized_number.rb +50 -0
  11. data/lib/twitter_cldr/localized/localized_object.rb +38 -0
  12. data/lib/twitter_cldr/localized/localized_string.rb +41 -0
  13. data/lib/twitter_cldr/localized/localized_symbol.rb +20 -0
  14. data/lib/twitter_cldr/localized/localized_time.rb +23 -0
  15. data/lib/twitter_cldr/localized/localized_timespan.rb +26 -0
  16. data/lib/twitter_cldr/localized.rb +18 -0
  17. data/lib/twitter_cldr/normalization.rb +23 -0
  18. data/lib/twitter_cldr/resources/{tries_dumper.rb → collation_tries_dumper.rb} +1 -1
  19. data/lib/twitter_cldr/resources/composition_exclusions_importer.rb +1 -1
  20. data/lib/twitter_cldr/resources/language_codes_importer.rb +232 -0
  21. data/lib/twitter_cldr/resources/locales_resources_importer.rb +1 -1
  22. data/lib/twitter_cldr/resources/phone_codes_importer.rb +1 -1
  23. data/lib/twitter_cldr/resources/postal_codes_importer.rb +1 -1
  24. data/lib/twitter_cldr/resources/tailoring_importer.rb +12 -3
  25. data/lib/twitter_cldr/resources/unicode_data_importer.rb +3 -1
  26. data/lib/twitter_cldr/resources.rb +2 -1
  27. data/lib/twitter_cldr/shared/calendar.rb +2 -6
  28. data/lib/twitter_cldr/shared/language_codes.rb +75 -0
  29. data/lib/twitter_cldr/shared/languages.rb +4 -11
  30. data/lib/twitter_cldr/shared.rb +8 -7
  31. data/lib/twitter_cldr/tokenizers/base.rb +2 -8
  32. data/lib/twitter_cldr/utils.rb +8 -0
  33. data/lib/twitter_cldr/version.rb +1 -1
  34. data/lib/twitter_cldr.rb +5 -4
  35. data/resources/custom/locales/cs/units.yml +3 -3
  36. data/resources/custom/locales/pl/units.yml +4 -4
  37. data/resources/custom/locales/pt/units.yml +2 -2
  38. data/resources/shared/language_codes_table.dump +0 -0
  39. data/spec/core_ext_spec.rb +19 -0
  40. data/spec/{core_ext/array_spec.rb → localized/localized_array_spec.rb} +1 -1
  41. data/spec/{core_ext/calendars/date_spec.rb → localized/localized_date_spec.rb} +24 -44
  42. data/spec/localized/localized_datetime_spec.rb +81 -0
  43. data/spec/{core_ext/numbers → localized}/localized_number_spec.rb +34 -1
  44. data/spec/localized/localized_object_spec.rb +89 -0
  45. data/spec/{core_ext/string_spec.rb → localized/localized_string_spec.rb} +16 -33
  46. data/spec/{core_ext/symbol_spec.rb → localized/localized_symbol_spec.rb} +3 -1
  47. data/spec/localized/localized_time_spec.rb +70 -0
  48. data/spec/normalization_spec.rb +42 -0
  49. data/spec/readme_spec.rb +51 -5
  50. data/spec/shared/language_codes_spec.rb +161 -0
  51. data/spec/shared/phone_codes_spec.rb +2 -2
  52. data/spec/shared/postal_codes_spec.rb +2 -2
  53. data/spec/spec_helper.rb +2 -0
  54. data/spec/tokenizers/base_spec.rb +15 -6
  55. data/spec/utils_spec.rb +18 -2
  56. data/twitter_cldr.gemspec +2 -1
  57. metadata +28 -44
  58. data/lib/twitter_cldr/core_ext/array.rb +0 -35
  59. data/lib/twitter_cldr/core_ext/calendars/date.rb +0 -25
  60. data/lib/twitter_cldr/core_ext/calendars/datetime.rb +0 -65
  61. data/lib/twitter_cldr/core_ext/calendars/time.rb +0 -25
  62. data/lib/twitter_cldr/core_ext/calendars/timespan.rb +0 -24
  63. data/lib/twitter_cldr/core_ext/localized_object.rb +0 -25
  64. data/lib/twitter_cldr/core_ext/numbers/bignum.rb +0 -8
  65. data/lib/twitter_cldr/core_ext/numbers/fixnum.rb +0 -8
  66. data/lib/twitter_cldr/core_ext/numbers/float.rb +0 -8
  67. data/lib/twitter_cldr/core_ext/numbers/localized_number.rb +0 -54
  68. data/lib/twitter_cldr/core_ext/string.rb +0 -51
  69. data/lib/twitter_cldr/core_ext/symbol.rb +0 -22
  70. data/spec/core_ext/calendars/datetime_spec.rb +0 -90
  71. data/spec/core_ext/calendars/time_spec.rb +0 -90
  72. data/spec/core_ext/calendars_spec.rb +0 -34
  73. data/spec/core_ext/numbers/bignum_spec.rb +0 -25
  74. data/spec/core_ext/numbers/fixnum_spec.rb +0 -25
  75. data/spec/core_ext/numbers/float_spec.rb +0 -25
  76. data/spec/core_ext/numbers_spec.rb +0 -39
@@ -5,7 +5,7 @@
5
5
 
6
6
  require 'cldr/export'
7
7
 
8
- require 'lib/twitter_cldr/resources/download'
8
+ require 'twitter_cldr/resources/download'
9
9
 
10
10
  module TwitterCldr
11
11
  module Resources
@@ -5,7 +5,7 @@
5
5
 
6
6
  require 'nokogiri'
7
7
 
8
- require 'lib/twitter_cldr/resources/download'
8
+ require 'twitter_cldr/resources/download'
9
9
 
10
10
  module TwitterCldr
11
11
  module Resources
@@ -5,7 +5,7 @@
5
5
 
6
6
  require 'nokogiri'
7
7
 
8
- require 'lib/twitter_cldr/resources/download'
8
+ require 'twitter_cldr/resources/download'
9
9
 
10
10
  module TwitterCldr
11
11
  module Resources
@@ -6,7 +6,7 @@
6
6
  require 'nokogiri'
7
7
  require 'java'
8
8
 
9
- require 'lib/twitter_cldr/resources/download'
9
+ require 'twitter_cldr/resources/download'
10
10
 
11
11
  module TwitterCldr
12
12
  module Resources
@@ -34,6 +34,8 @@ module TwitterCldr
34
34
 
35
35
  EMPTY_TAILORING_DATA = { :collator_options => {}, :tailored_table => '', :suppressed_contractions => '' }
36
36
 
37
+ ICU4J_URL = 'http://download.icu-project.org/files/icu4j/49.1/icu4j-49_1.jar'
38
+
37
39
  class ImportError < RuntimeError; end
38
40
 
39
41
  # Arguments:
@@ -43,7 +45,7 @@ module TwitterCldr
43
45
  # icu4j_path - path to ICU4J jar file
44
46
  #
45
47
  def initialize(input_path, output_path, icu4j_path)
46
- require icu4j_path
48
+ require_icu4j(icu4j_path)
47
49
 
48
50
  @input_path = input_path
49
51
  @output_path = output_path
@@ -56,6 +58,11 @@ module TwitterCldr
56
58
 
57
59
  private
58
60
 
61
+ def require_icu4j(icu4j_path)
62
+ TwitterCldr::Resources.download_if_necessary(icu4j_path, ICU4J_URL)
63
+ require icu4j_path
64
+ end
65
+
59
66
  def import_locale(locale)
60
67
  print "Importing %8s\t--\t" % locale
61
68
 
@@ -126,7 +133,7 @@ module TwitterCldr
126
133
  end
127
134
  elsif child.name == 'x'
128
135
  context = ''
129
- child.children.each_with_object([]) do |c, memo|
136
+ child.children.inject([]) do |memo, c|
130
137
  if SIMPLE_RULES.include?(c.name)
131
138
  memo << table_entry_for_rule(collator, context + c.text)
132
139
  elsif c.name == 'context'
@@ -134,6 +141,8 @@ module TwitterCldr
134
141
  elsif c.name != 'extend'
135
142
  raise ImportError, "Rule '#{c.name}' inside <x></x> is not supported."
136
143
  end
144
+
145
+ memo
137
146
  end
138
147
  else
139
148
  raise ImportError, "Tag '#{child.name}' is not supported." unless IGNORED_TAGS.include?(child.name)
@@ -3,7 +3,7 @@
3
3
  # Copyright 2012 Twitter, Inc
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
- require 'lib/twitter_cldr/resources/download'
6
+ require 'twitter_cldr/resources/download'
7
7
 
8
8
  module TwitterCldr
9
9
  module Resources
@@ -29,6 +29,8 @@ module TwitterCldr
29
29
 
30
30
  File.open(File.join(@output_path, 'blocks.yml'), 'w') { |output| YAML.dump(blocks, output) }
31
31
 
32
+ FileUtils.mkdir_p(File.join(@output_path, 'blocks'))
33
+
32
34
  unicode_data.each do |block_name, code_points|
33
35
  File.open(File.join(@output_path, 'blocks', "#{block_name}.yml"), 'w') { |output| YAML.dump(code_points, output) }
34
36
  end
@@ -6,14 +6,15 @@
6
6
  module TwitterCldr
7
7
  module Resources
8
8
  autoload :CanonicalCompositionsUpdater, 'twitter_cldr/resources/canonical_compositions_updater'
9
+ autoload :CollationTriesDumper, 'twitter_cldr/resources/collation_tries_dumper'
9
10
  autoload :CompositionExclusionsImporter, 'twitter_cldr/resources/composition_exclusions_importer'
10
11
  autoload :CustomLocalesResourcesImporter, 'twitter_cldr/resources/custom_locales_resources_importer'
12
+ autoload :LanguageCodesImporter, 'twitter_cldr/resources/language_codes_importer'
11
13
  autoload :Loader, 'twitter_cldr/resources/loader'
12
14
  autoload :LocalesResourcesImporter, 'twitter_cldr/resources/locales_resources_importer'
13
15
  autoload :PhoneCodesImporter, 'twitter_cldr/resources/phone_codes_importer'
14
16
  autoload :PostalCodesImporter, 'twitter_cldr/resources/postal_codes_importer'
15
17
  autoload :TailoringImporter, 'twitter_cldr/resources/tailoring_importer'
16
- autoload :TriesDumper, 'twitter_cldr/resources/tries_dumper'
17
18
  autoload :UnicodeDataImporter, 'twitter_cldr/resources/unicode_data_importer'
18
19
  end
19
20
  end
@@ -34,15 +34,11 @@ module TwitterCldr
34
34
  end
35
35
 
36
36
  def get_data(*path)
37
- data = traverse_path(calendar_data, path)
37
+ data = TwitterCldr::Utils.traverse_hash(calendar_data, path)
38
38
  redirect = parse_redirect(data)
39
39
  redirect ? get_data(*redirect) : data
40
40
  end
41
41
 
42
- def traverse_path(tree, path)
43
- !path.empty? && tree.is_a?(Hash) ? traverse_path(tree[path.first], path[1..-1]) : tree
44
- end
45
-
46
42
  def parse_redirect(data)
47
43
  $1.split('.').map(&:to_sym) if data.is_a?(Symbol) && data.to_s =~ redirect_regexp
48
44
  end
@@ -52,7 +48,7 @@ module TwitterCldr
52
48
  end
53
49
 
54
50
  def calendar_data
55
- @calendar_data ||= traverse_path(resource, [locale, :calendars, calendar_type])
51
+ @calendar_data ||= TwitterCldr::Utils.traverse_hash(resource, [locale, :calendars, calendar_type])
56
52
  end
57
53
 
58
54
  def resource
@@ -0,0 +1,75 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ module TwitterCldr
7
+ module Shared
8
+ module LanguageCodes
9
+
10
+ LANGUAGE_CODES_DUMP_PATH = File.join(TwitterCldr::RESOURCES_DIR, 'shared', 'language_codes_table.dump')
11
+
12
+ NAME_STANDARD = :name # fake standard, mostly for internal use
13
+
14
+ VALID_STANDARDS = [:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3, NAME_STANDARD]
15
+
16
+ class << self
17
+
18
+ def languages
19
+ resource[NAME_STANDARD].keys
20
+ end
21
+
22
+ def valid_standard?(standard)
23
+ VALID_STANDARDS.include?(standard.to_sym)
24
+ end
25
+
26
+ def valid_code?(code, standard)
27
+ resource[validate_standard(standard)].has_key?(code.to_sym)
28
+ end
29
+
30
+ def convert(code, from_and_to = {})
31
+ from, to = extract_from_and_to_options(from_and_to)
32
+ resource[from].fetch(code.to_sym, {})[to]
33
+ end
34
+
35
+ def from_language(language, standard)
36
+ convert(language, :from => NAME_STANDARD, :to => standard)
37
+ end
38
+
39
+ def to_language(code, standard)
40
+ convert(code, :from => standard, :to => NAME_STANDARD).to_s
41
+ end
42
+
43
+ def standards_for(code, standard)
44
+ resource[validate_standard(standard)].fetch(code.to_sym, {}).keys - [NAME_STANDARD] # exclude fake NAME_STANDARD standard
45
+ end
46
+
47
+ def standards_for_language(language)
48
+ standards_for(language, NAME_STANDARD)
49
+ end
50
+
51
+ private
52
+
53
+ def resource
54
+ @resource ||= File.open(LANGUAGE_CODES_DUMP_PATH) { |file| Marshal.load(file.read) }
55
+ end
56
+
57
+ def extract_from_and_to_options(from_and_to)
58
+ TwitterCldr::Utils.deep_symbolize_keys(from_and_to).values_at(:from, :to).map do |standard|
59
+ raise ArgumentError, 'options :from and :to are required' if standard.nil?
60
+ validate_standard(standard)
61
+ end
62
+ end
63
+
64
+ def validate_standard(standard)
65
+ raise ArgumentError, "standard can't be nil" if standard.nil?
66
+ raise ArgumentError, "#{standard.inspect} is not a valid standard name" unless valid_standard?(standard)
67
+
68
+ standard.to_sym
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -14,7 +14,7 @@ module TwitterCldr
14
14
  end
15
15
 
16
16
  def all_for(code)
17
- get_resource(TwitterCldr.convert_locale(code.to_sym))[:languages]
17
+ get_resource(code)[:languages]
18
18
  rescue
19
19
  {}
20
20
  end
@@ -24,21 +24,14 @@ module TwitterCldr
24
24
  end
25
25
 
26
26
  def from_code_for_locale(code, locale = TwitterCldr.get_locale)
27
- get_resource(TwitterCldr.convert_locale(locale.to_sym))[:languages][TwitterCldr.convert_locale(code.to_sym)]
27
+ get_resource(locale)[:languages][TwitterCldr.convert_locale(code)]
28
28
  rescue
29
29
  nil
30
30
  end
31
31
 
32
32
  def translate_language(language, source_locale = :en, dest_locale = TwitterCldr.get_locale)
33
- source_locale = TwitterCldr.convert_locale(source_locale.to_sym)
34
- lang_code = get_resource(source_locale)[:languages].select { |key, val| val.downcase == language.downcase }.flatten.first
35
-
36
- if lang_code
37
- dest_locale = TwitterCldr.convert_locale(dest_locale.to_sym)
38
- get_resource(dest_locale)[:languages][lang_code.to_sym]
39
- else
40
- nil
41
- end
33
+ lang_code = get_resource(source_locale)[:languages].detect { |_, val| val.downcase == language.downcase }.first
34
+ get_resource(dest_locale)[:languages][lang_code] if lang_code
42
35
  rescue
43
36
  nil
44
37
  end
@@ -5,12 +5,13 @@
5
5
 
6
6
  module TwitterCldr
7
7
  module Shared
8
- autoload :Calendar, 'twitter_cldr/shared/calendar'
9
- autoload :CodePoint, 'twitter_cldr/shared/code_point'
10
- autoload :Currencies, 'twitter_cldr/shared/currencies'
11
- autoload :Languages, 'twitter_cldr/shared/languages'
12
- autoload :Numbers, 'twitter_cldr/shared/numbers'
13
- autoload :PhoneCodes, 'twitter_cldr/shared/phone_codes'
14
- autoload :PostalCodes, 'twitter_cldr/shared/postal_codes'
8
+ autoload :Calendar, 'twitter_cldr/shared/calendar'
9
+ autoload :CodePoint, 'twitter_cldr/shared/code_point'
10
+ autoload :Currencies, 'twitter_cldr/shared/currencies'
11
+ autoload :LanguageCodes, 'twitter_cldr/shared/language_codes'
12
+ autoload :Languages, 'twitter_cldr/shared/languages'
13
+ autoload :Numbers, 'twitter_cldr/shared/numbers'
14
+ autoload :PhoneCodes, 'twitter_cldr/shared/phone_codes'
15
+ autoload :PostalCodes, 'twitter_cldr/shared/postal_codes'
15
16
  end
16
17
  end
@@ -90,14 +90,8 @@ module TwitterCldr
90
90
  @placeholders = {}
91
91
  end
92
92
 
93
- def traverse(path, haystack = @resource)
94
- path.inject(haystack) do |current, segment|
95
- if current.is_a?(Hash) && current.has_key?(segment)
96
- current[segment]
97
- else
98
- return
99
- end
100
- end
93
+ def traverse(path, hash = @resource)
94
+ TwitterCldr::Utils.traverse_hash(hash, path)
101
95
  end
102
96
 
103
97
  # expands all path symbols
@@ -41,6 +41,14 @@ module TwitterCldr
41
41
  end
42
42
  end
43
43
 
44
+ def traverse_hash(hash, path)
45
+ return if path.empty?
46
+
47
+ path.inject(hash) do |current, key|
48
+ current.is_a?(Hash) ? current[key] : return
49
+ end
50
+ end
51
+
44
52
  end
45
53
 
46
54
  end
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = "1.7.0"
7
+ VERSION = "1.8.0"
8
8
  end
data/lib/twitter_cldr.rb CHANGED
@@ -3,9 +3,6 @@
3
3
  # Copyright 2012 Twitter, Inc
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
- $:.push(File.dirname(__FILE__))
7
- $:.push(File.dirname(File.dirname(__FILE__)))
8
-
9
6
  $KCODE = 'UTF-8' unless RUBY_VERSION >= '1.9.0'
10
7
 
11
8
  require 'yaml'
@@ -22,6 +19,7 @@ module TwitterCldr
22
19
 
23
20
  autoload :Formatters, 'twitter_cldr/formatters'
24
21
  autoload :Collation, 'twitter_cldr/collation'
22
+ autoload :Localized, 'twitter_cldr/localized'
25
23
  autoload :Normalization, 'twitter_cldr/normalization'
26
24
  autoload :Resources, 'twitter_cldr/resources'
27
25
  autoload :Shared, 'twitter_cldr/shared'
@@ -38,6 +36,8 @@ module TwitterCldr
38
36
 
39
37
  RESOURCES_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'resources')
40
38
 
39
+ JS_LIB_DIR = File.join(File.dirname(File.dirname(__FILE__)), 'js', 'lib')
40
+
41
41
  # maps twitter locales to cldr locales
42
42
  TWITTER_LOCALE_MAP = {
43
43
  :msa => :ms,
@@ -88,7 +88,8 @@ module TwitterCldr
88
88
  end
89
89
 
90
90
  def require_js
91
- require "js/lib/twitter_cldr_js"
91
+ $:.push(JS_LIB_DIR) unless $:.include?(JS_LIB_DIR)
92
+ require 'twitter_cldr_js'
92
93
  end
93
94
  end
94
95
 
@@ -18,6 +18,6 @@
18
18
  :other: ! '{0}min'
19
19
  :second:
20
20
  :abbreviated:
21
- :one: ! '{0}s'
22
- :few: ! '{0}s'
23
- :other: ! '{0}s'
21
+ :one: ! '{0}sec'
22
+ :few: ! '{0}sec'
23
+ :other: ! '{0}sec'
@@ -15,10 +15,10 @@
15
15
  :other: ! '{0}godz.'
16
16
  :minute:
17
17
  :abbreviated:
18
- :one: ! '{0}min'
19
- :few: ! '{0}min'
20
- :many: ! '{0}min'
21
- :other: ! '{0}min'
18
+ :one: ! '{0} min'
19
+ :few: ! '{0} min'
20
+ :many: ! '{0} min'
21
+ :other: ! '{0} min'
22
22
  :second:
23
23
  :abbreviated:
24
24
  :one: ! '{0}s'
@@ -15,5 +15,5 @@
15
15
  :other: ! '{0} m'
16
16
  :second:
17
17
  :abbreviated:
18
- :one: ! '{0}s'
19
- :other: ! '{0}s'
18
+ :one: ! '{0} s'
19
+ :other: ! '{0} s'
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
8
+ describe 'Core classes localization' do
9
+
10
+ [Array, Bignum, Date, DateTime, Fixnum, Float, String, Symbol, Time].each do |klass|
11
+ describe klass do
12
+ it 'has public instance method #localize' do
13
+ # convert methods names to symbols (they're strings in 1.8)
14
+ klass.public_instance_methods.map(&:to_sym).should include(:localize)
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  require 'spec_helper'
7
7
 
8
- include TwitterCldr
8
+ include TwitterCldr::Localized
9
9
 
10
10
  describe LocalizedArray do
11
11
  describe '#code_points_to_string' do
@@ -5,42 +5,13 @@
5
5
 
6
6
  require 'spec_helper'
7
7
 
8
- include TwitterCldr
8
+ include TwitterCldr::Localized
9
9
 
10
- describe Date do
11
- describe "#localize" do
12
- before(:all) do
13
- @date = Date.today
14
- end
15
-
16
- it "should localize with the given locale, English by default" do
17
- loc_date = @date.localize
18
- loc_date.should be_a(LocalizedDate)
19
- loc_date.locale.should == :en
20
- loc_date.calendar_type.should == :gregorian
21
- loc_date.base_obj.should == @date
22
-
23
- loc_date = @date.localize(:it)
24
- loc_date.should be_a(LocalizedDate)
25
- loc_date.locale.should == :it
26
- end
27
-
28
- it "should localize with the given calendar" do
29
- loc_date = @date.localize(:th, :calendar_type => :buddhist)
30
- loc_date.should be_a(LocalizedDate)
31
- loc_date.locale.should == :th
32
- loc_date.calendar_type.should == :buddhist
33
- loc_date.base_obj.should == @date
34
- end
10
+ describe LocalizedDate do
35
11
 
36
- it "should forward calendar_type" do
37
- loc_date = @date.localize(:th, :calendar_type => :buddhist)
38
- loc_date.to_datetime(Time.now).calendar_type.should == :buddhist
39
- end
12
+ let(:date) { Date.today }
40
13
 
41
- end
42
-
43
- describe "ago" do
14
+ describe "#ago" do
44
15
  let(:date) { Date.new(2010,7,6) }
45
16
  let(:base_time) { Time.gm(2010,8,6,12,12,30) }
46
17
 
@@ -91,7 +62,7 @@ describe Date do
91
62
  end
92
63
  end
93
64
 
94
- describe "until" do
65
+ describe "#until" do
95
66
  let(:base_time) { Time.gm(2010,8,6,12,12,30) }
96
67
 
97
68
  it "should until-ify with a number of different units" do
@@ -114,10 +85,10 @@ describe Date do
114
85
 
115
86
  describe "stringify" do
116
87
  it "should stringify with a default calendar" do
117
- #Date.today.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
118
- Date.today.localize(:th).to_long_s
119
- Date.today.localize(:th).to_medium_s
120
- Date.today.localize(:th).to_short_s
88
+ #date.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
89
+ date.localize(:th).to_long_s
90
+ date.localize(:th).to_medium_s
91
+ date.localize(:th).to_short_s
121
92
  end
122
93
 
123
94
  it "should stringify with buddhist calendar" do
@@ -126,15 +97,13 @@ describe Date do
126
97
  be_nil, 'buddhist calendar is missing for :th locale (check resources/locales/th/calendars.yml)'
127
98
  )
128
99
 
129
- #Date.today.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
130
- Date.today.localize(:th, :calendar_type => :buddhist).to_long_s
131
- Date.today.localize(:th, :calendar_type => :buddhist).to_medium_s
132
- Date.today.localize(:th, :calendar_type => :buddhist).to_short_s
100
+ #date.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
101
+ date.localize(:th, :calendar_type => :buddhist).to_long_s
102
+ date.localize(:th, :calendar_type => :buddhist).to_medium_s
103
+ date.localize(:th, :calendar_type => :buddhist).to_short_s
133
104
  end
134
105
  end
135
- end
136
106
 
137
- describe LocalizedDate do
138
107
  describe "#to_datetime" do
139
108
  it "should combine a date and a time object into a datetime" do
140
109
  date = Date.new(1987, 9, 20)
@@ -152,4 +121,15 @@ describe LocalizedDate do
152
121
  datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S").should == "1987-09-20 22:05:00"
153
122
  end
154
123
  end
124
+
125
+ describe 'formatters' do
126
+ it "don't raise errors for any locale" do
127
+ TwitterCldr.supported_locales.each do |locale|
128
+ TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES.each do |type|
129
+ lambda { Date.today.localize(locale).send(:"to_#{type}_s") }.should_not raise_error
130
+ end
131
+ end
132
+ end
133
+ end
134
+
155
135
  end