twitter_cldr 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. data/Gemfile +32 -0
  2. data/History.txt +78 -0
  3. data/README.md +72 -62
  4. data/Rakefile +22 -0
  5. data/js/lib/compiler.rb +40 -0
  6. data/js/lib/mustache/bundle.coffee +14 -0
  7. data/js/lib/mustache/calendars/datetime.coffee +240 -0
  8. data/js/lib/mustache/calendars/timespan.coffee +52 -0
  9. data/js/lib/mustache/plurals/rules.coffee +14 -0
  10. data/js/lib/renderers/base.rb +18 -0
  11. data/js/lib/renderers/bundle.rb +18 -0
  12. data/js/lib/renderers/calendars/datetime_renderer.rb +34 -0
  13. data/js/lib/renderers/calendars/timespan_renderer.rb +39 -0
  14. data/js/lib/renderers/plurals/rules/plural_rules_compiler.rb +89 -0
  15. data/js/lib/renderers/plurals/rules/plural_rules_renderer.rb +26 -0
  16. data/js/lib/twitter_cldr_js.rb +85 -0
  17. data/js/spec/js/calendars/datetime_spec.js +418 -0
  18. data/js/spec/js/calendars/timespan_spec.js +91 -0
  19. data/js/spec/js/plurals/plural_rules_spec.js +28 -0
  20. data/js/spec/js/support/jasmine.yml +8 -0
  21. data/js/spec/rb/renderers/plurals/plural_rules_compiler_spec.rb +52 -0
  22. data/js/spec/rb/spec_helper.rb +13 -0
  23. data/lib/twitter_cldr.rb +2 -1
  24. data/lib/twitter_cldr/collation.rb +2 -1
  25. data/lib/twitter_cldr/collation/collator.rb +49 -31
  26. data/lib/twitter_cldr/collation/{sort_key.rb → sort_key_builder.rb} +31 -8
  27. data/lib/twitter_cldr/collation/trie.rb +116 -24
  28. data/lib/twitter_cldr/collation/trie_builder.rb +54 -28
  29. data/lib/twitter_cldr/collation/trie_with_fallback.rb +55 -0
  30. data/lib/twitter_cldr/core_ext/array.rb +14 -1
  31. data/lib/twitter_cldr/core_ext/calendars/datetime.rb +8 -2
  32. data/lib/twitter_cldr/core_ext/calendars/timespan.rb +5 -5
  33. data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +10 -10
  34. data/lib/twitter_cldr/formatters/plurals/rules.rb +3 -5
  35. data/lib/twitter_cldr/resources.rb +11 -0
  36. data/lib/twitter_cldr/resources/import.rb +12 -0
  37. data/lib/twitter_cldr/resources/import/tailoring.rb +193 -0
  38. data/lib/twitter_cldr/{shared/resources.rb → resources/loader.rb} +17 -4
  39. data/lib/twitter_cldr/shared.rb +0 -1
  40. data/lib/twitter_cldr/tokenizers/base.rb +9 -9
  41. data/lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb +0 -4
  42. data/lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb +21 -7
  43. data/lib/twitter_cldr/utils.rb +11 -0
  44. data/lib/twitter_cldr/version.rb +1 -1
  45. data/resources/collation/tailoring/af.yml +3 -0
  46. data/resources/collation/tailoring/ar.yml +21 -0
  47. data/resources/collation/tailoring/ca.yml +9 -0
  48. data/resources/collation/tailoring/cs.yml +25 -0
  49. data/resources/collation/tailoring/da.yml +59 -0
  50. data/resources/collation/tailoring/de.yml +3 -0
  51. data/resources/collation/tailoring/el.yml +3 -0
  52. data/resources/collation/tailoring/en.yml +3 -0
  53. data/resources/collation/tailoring/es.yml +5 -0
  54. data/resources/collation/tailoring/eu.yml +3 -0
  55. data/resources/collation/tailoring/fa.yml +73 -0
  56. data/resources/collation/tailoring/fi.yml +61 -0
  57. data/resources/collation/tailoring/fil.yml +11 -0
  58. data/resources/collation/tailoring/fr.yml +3 -0
  59. data/resources/collation/tailoring/he.yml +3 -0
  60. data/resources/collation/tailoring/hi.yml +7 -0
  61. data/resources/collation/tailoring/hu.yml +125 -0
  62. data/resources/collation/tailoring/id.yml +3 -0
  63. data/resources/collation/tailoring/it.yml +3 -0
  64. data/resources/collation/tailoring/ja.yml +14647 -0
  65. data/resources/collation/tailoring/ko.yml +14953 -0
  66. data/resources/collation/tailoring/ms.yml +3 -0
  67. data/resources/collation/tailoring/nb.yml +59 -0
  68. data/resources/collation/tailoring/nl.yml +3 -0
  69. data/resources/collation/tailoring/pl.yml +37 -0
  70. data/resources/collation/tailoring/pt.yml +3 -0
  71. data/resources/collation/tailoring/ru.yml +3 -0
  72. data/resources/collation/tailoring/sv.yml +63 -0
  73. data/resources/collation/tailoring/th.yml +19 -0
  74. data/resources/collation/tailoring/tr.yml +27 -0
  75. data/resources/collation/tailoring/uk.yml +5 -0
  76. data/resources/collation/tailoring/ur.yml +163 -0
  77. data/resources/collation/tailoring/zh-Hant.yml +3 -0
  78. data/resources/collation/tailoring/zh.yml +149 -0
  79. data/resources/custom/locales/af/units.yml +19 -0
  80. data/resources/custom/locales/ar/units.yml +35 -0
  81. data/resources/custom/locales/ca/units.yml +19 -0
  82. data/resources/custom/locales/cs/units.yml +23 -0
  83. data/resources/custom/locales/da/units.yml +19 -0
  84. data/resources/custom/locales/de/units.yml +19 -0
  85. data/resources/custom/locales/el/units.yml +19 -0
  86. data/resources/custom/locales/en/units.yml +18 -0
  87. data/resources/custom/locales/es/units.yml +19 -0
  88. data/resources/custom/locales/eu/units.yml +19 -0
  89. data/resources/custom/locales/fa/units.yml +15 -0
  90. data/resources/custom/locales/fi/units.yml +19 -0
  91. data/resources/custom/locales/fil/units.yml +19 -0
  92. data/resources/custom/locales/fr/units.yml +19 -0
  93. data/resources/custom/locales/he/units.yml +19 -0
  94. data/resources/custom/locales/hi/units.yml +19 -0
  95. data/resources/custom/locales/hu/units.yml +15 -0
  96. data/resources/custom/locales/id/units.yml +15 -0
  97. data/resources/custom/locales/it/units.yml +19 -0
  98. data/resources/custom/locales/ja/units.yml +15 -0
  99. data/resources/custom/locales/ko/units.yml +15 -0
  100. data/resources/custom/locales/ms/units.yml +15 -0
  101. data/resources/custom/locales/nb/units.yml +19 -0
  102. data/resources/custom/locales/nl/units.yml +19 -0
  103. data/resources/custom/locales/pl/units.yml +23 -0
  104. data/resources/custom/locales/pt/units.yml +19 -0
  105. data/resources/custom/locales/ru/units.yml +27 -0
  106. data/resources/custom/locales/sv/units.yml +19 -0
  107. data/resources/custom/locales/th/units.yml +15 -0
  108. data/resources/custom/locales/tr/units.yml +15 -0
  109. data/resources/custom/locales/uk/units.yml +27 -0
  110. data/resources/custom/locales/ur/units.yml +19 -0
  111. data/resources/custom/locales/zh-Hant/units.yml +15 -0
  112. data/resources/custom/locales/zh/units.yml +15 -0
  113. data/resources/locales/af/units.yml +112 -65
  114. data/resources/locales/ar/units.yml +196 -126
  115. data/resources/locales/ca/units.yml +112 -70
  116. data/resources/locales/cs/units.yml +140 -91
  117. data/resources/locales/da/units.yml +98 -56
  118. data/resources/locales/de/units.yml +112 -70
  119. data/resources/locales/el/units.yml +119 -84
  120. data/resources/locales/en/units.yml +84 -42
  121. data/resources/locales/es/units.yml +112 -70
  122. data/resources/locales/eu/units.yml +105 -68
  123. data/resources/locales/fa/units.yml +98 -63
  124. data/resources/locales/fi/units.yml +112 -70
  125. data/resources/locales/fil/units.yml +98 -56
  126. data/resources/locales/fr/units.yml +112 -70
  127. data/resources/locales/he/units.yml +98 -56
  128. data/resources/locales/hi/units.yml +98 -56
  129. data/resources/locales/hu/units.yml +84 -49
  130. data/resources/locales/id/units.yml +84 -49
  131. data/resources/locales/it/units.yml +98 -56
  132. data/resources/locales/ja/units.yml +84 -49
  133. data/resources/locales/ko/units.yml +84 -49
  134. data/resources/locales/ms/units.yml +112 -63
  135. data/resources/locales/nb/units.yml +106 -64
  136. data/resources/locales/nl/units.yml +98 -56
  137. data/resources/locales/pl/units.yml +181 -112
  138. data/resources/locales/pt/units.yml +112 -70
  139. data/resources/locales/ru/units.yml +168 -112
  140. data/resources/locales/sv/units.yml +112 -70
  141. data/resources/locales/th/units.yml +84 -49
  142. data/resources/locales/tr/units.yml +84 -49
  143. data/resources/locales/uk/units.yml +168 -112
  144. data/resources/locales/ur/units.yml +112 -63
  145. data/resources/locales/zh-Hant/units.yml +84 -49
  146. data/resources/locales/zh/units.yml +84 -49
  147. data/spec/collation/collation_spec.rb +1 -1
  148. data/spec/collation/collator_spec.rb +120 -48
  149. data/spec/collation/sort_key_builder_spec.rb +80 -0
  150. data/spec/collation/tailoring_spec.rb +137 -0
  151. data/spec/collation/tailoring_tests/af.txt +321 -0
  152. data/spec/collation/tailoring_tests/ar.txt +188 -0
  153. data/spec/collation/tailoring_tests/ca.txt +446 -0
  154. data/spec/collation/tailoring_tests/cs.txt +273 -0
  155. data/spec/collation/tailoring_tests/da.txt +293 -0
  156. data/spec/collation/tailoring_tests/de.txt +414 -0
  157. data/spec/collation/tailoring_tests/el.txt +228 -0
  158. data/spec/collation/tailoring_tests/en.txt +399 -0
  159. data/spec/collation/tailoring_tests/es.txt +402 -0
  160. data/spec/collation/tailoring_tests/eu.txt +183 -0
  161. data/spec/collation/tailoring_tests/fa.txt +263 -0
  162. data/spec/collation/tailoring_tests/fi.txt +389 -0
  163. data/spec/collation/tailoring_tests/fil.txt +279 -0
  164. data/spec/collation/tailoring_tests/fr.txt +363 -0
  165. data/spec/collation/tailoring_tests/he.txt +167 -0
  166. data/spec/collation/tailoring_tests/hi.txt +230 -0
  167. data/spec/collation/tailoring_tests/hu.txt +773 -0
  168. data/spec/collation/tailoring_tests/id.txt +171 -0
  169. data/spec/collation/tailoring_tests/it.txt +231 -0
  170. data/spec/collation/tailoring_tests/ja.txt +4287 -0
  171. data/spec/collation/tailoring_tests/ko.txt +1761 -0
  172. data/spec/collation/tailoring_tests/ms.txt +531 -0
  173. data/spec/collation/tailoring_tests/nb.txt +375 -0
  174. data/spec/collation/tailoring_tests/nl.txt +273 -0
  175. data/spec/collation/tailoring_tests/pl.txt +225 -0
  176. data/spec/collation/tailoring_tests/pt.txt +405 -0
  177. data/spec/collation/tailoring_tests/ru.txt +213 -0
  178. data/spec/collation/tailoring_tests/sv.txt +353 -0
  179. data/spec/collation/tailoring_tests/th.txt +239 -0
  180. data/spec/collation/tailoring_tests/tr.txt +414 -0
  181. data/spec/collation/tailoring_tests/uk.txt +218 -0
  182. data/spec/collation/tailoring_tests/ur.txt +284 -0
  183. data/spec/collation/tailoring_tests/zh-Hant.txt +626 -0
  184. data/spec/collation/tailoring_tests/zh.txt +717 -0
  185. data/spec/collation/trie_builder_spec.rb +131 -51
  186. data/spec/collation/trie_spec.rb +301 -26
  187. data/spec/collation/trie_with_fallback_spec.rb +41 -0
  188. data/spec/core_ext/array_spec.rb +46 -3
  189. data/spec/core_ext/calendars/date_spec.rb +24 -24
  190. data/spec/core_ext/calendars/datetime_spec.rb +7 -0
  191. data/spec/core_ext/calendars/time_spec.rb +2 -2
  192. data/spec/formatters/calendars/timespan_formatter_spec.rb +47 -18
  193. data/spec/formatters/plurals/rules_spec.rb +3 -11
  194. data/spec/readme_spec.rb +15 -15
  195. data/spec/resources/loader_spec.rb +94 -0
  196. data/spec/spec_helper.rb +6 -0
  197. data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +1 -1
  198. data/spec/twitter_cldr_spec.rb +3 -3
  199. data/spec/utils_spec.rb +38 -0
  200. data/twitter_cldr.gemspec +25 -0
  201. metadata +156 -110
  202. data/spec/collation/sort_key_spec.rb +0 -56
  203. data/spec/shared/resources_spec.rb +0 -75
@@ -0,0 +1,26 @@
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 Js
8
+ module Renderers
9
+ module PluralRules
10
+
11
+ class PluralRulesRenderer < TwitterCldr::Js::Renderers::Base
12
+ self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../../..", "mustache/plurals/rules.coffee"))
13
+
14
+ def rules
15
+ ruby_str = TwitterCldr.get_locale_resource(@locale, :plurals)[@locale]
16
+ rule_str = ruby_str.scan(/lambda\s*\{\s*\|n\|(.*?)\}/).first.first.strip
17
+ js_str = PluralRulesCompiler.rule_to_js(rule_str)
18
+ hash = eval(ruby_str)
19
+ %Q({"keys": #{hash[@locale][:i18n][:plural][:keys].to_json}, "rule": #{js_str}})
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ $:.push(File.dirname(__FILE__))
7
+
8
+ require 'mustache'
9
+ require 'uglifier'
10
+ require 'jasmine-headless-webkit'
11
+ require 'coffee-script'
12
+ require 'json'
13
+
14
+ require 'compiler'
15
+ require 'renderers/bundle'
16
+ require 'renderers/base'
17
+
18
+ require 'renderers/calendars/datetime_renderer'
19
+ require 'renderers/calendars/timespan_renderer'
20
+ require 'renderers/plurals/rules/plural_rules_compiler'
21
+ require 'renderers/plurals/rules/plural_rules_renderer'
22
+
23
+ module TwitterCldr
24
+ module Js
25
+ def self.build(options = {})
26
+ TwitterCldr::Js::Compiler.new(options).compile do |bundle, locale|
27
+ cur_file = (options[:file_name] || "twitter_cldr_%{locale}.js").gsub("%{locale}", locale.to_s)
28
+
29
+ if options[:minify]
30
+ ext = File.extname(cur_file)
31
+ min_file = "#{cur_file.chomp(File.extname(cur_file))}.min#{ext}"
32
+ File.open(File.join(build_dir, min_file), "w+") do |f|
33
+ f.write(Uglifier.compile(bundle))
34
+ end
35
+ else
36
+ File.open(File.join(build_dir, cur_file), "w+") do |f|
37
+ f.write(bundle)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.clean(output_dir = build_dir)
44
+ FileUtils.rm_rf(Dir.glob(File.join(build_dir, "**")))
45
+ end
46
+
47
+ def self.build_dir
48
+ File.join(File.dirname(File.dirname(__FILE__)), "build")
49
+ end
50
+
51
+ def self.output_dir
52
+ @output_dir ||= build_dir
53
+ end
54
+
55
+ def self.output_dir=(new_dir)
56
+ @output_dir = new_dir
57
+ end
58
+
59
+ def self.make(options = {})
60
+ # clean dir, then build js
61
+ FileUtils.rm_rf(Dir.glob(File.join(build_dir, "**")))
62
+ build(options)
63
+ build(options.merge({ :minify => true }))
64
+ end
65
+
66
+ def self.test
67
+ Dir.chdir(File.dirname(__FILE__)) do
68
+ Jasmine::Headless::Runner.run(:colors => true, :jasmine_config => File.expand_path("../spec/js/support/jasmine.yml"))
69
+ end
70
+ end
71
+
72
+ def self.install
73
+ FileUtils.mkdir_p(output_dir)
74
+ Dir.glob(File.join(build_dir, "**/**")).each do |source_file|
75
+ if File.file?(source_file)
76
+ dest_file = File.join(output_dir, source_file.gsub(build_dir, ""))
77
+ FileUtils.cp(source_file, dest_file)
78
+ end
79
+ end
80
+ File.open(File.join(output_dir, "VERSION"), "w+") { |f| f.write(TwitterCldr::VERSION) }
81
+ File.open(File.join(output_dir, "CLDR_VERSION"), "w+") { |f| f.write(TwitterCldr::CLDR_VERSION) }
82
+ FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), "../../LICENSE")), output_dir)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,418 @@
1
+ // Copyright 2012 Twitter, Inc
2
+ // http://www.apache.org/licenses/LICENSE-2.0
3
+
4
+ //= require '../../../build/twitter_cldr_en.js'
5
+
6
+ describe("DateTimeFormatter", function() {
7
+ beforeEach(function() {
8
+ formatter = new TwitterCldr.DateTimeFormatter();
9
+ });
10
+
11
+ describe("#day", function() {
12
+ it("test: pattern d", function() {
13
+ expect(formatter.day(new Date(2010, 0, 1), 'd', 1)).toEqual('1');
14
+ expect(formatter.day(new Date(2010, 0, 10), 'd', 1)).toEqual('10');
15
+ });
16
+
17
+ it("test: pattern dd", function() {
18
+ expect(formatter.day(new Date(2010, 0, 1), 'dd', 2)).toEqual('01');
19
+ expect(formatter.day(new Date(2010, 0, 10), 'dd', 2)).toEqual('10');
20
+ });
21
+ });
22
+
23
+ describe("#weekday_local_stand_alone", function() {
24
+ it("test: pattern c", function() {
25
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'c', 1)).toEqual('1');
26
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'c', 1)).toEqual('2');
27
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'c', 1)).toEqual('7');
28
+ });
29
+
30
+ it("test: pattern cc", function() {
31
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'cc', 2)).toEqual('Mon');
32
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'cc', 2)).toEqual('Tue');
33
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'cc', 2)).toEqual('Sun');
34
+ });
35
+
36
+ it("test: pattern ccc", function() {
37
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'ccc', 3)).toEqual('Mon');
38
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'ccc', 3)).toEqual('Tue');
39
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'ccc', 3)).toEqual('Sun');
40
+ });
41
+
42
+ it("test: pattern cccc", function() {
43
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'cccc', 4)).toEqual('Monday');
44
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'cccc', 4)).toEqual('Tuesday');
45
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'cccc', 4)).toEqual('Sunday');
46
+ });
47
+
48
+ it("test: pattern ccccc", function() {
49
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 4), 'ccccc', 5)).toEqual('M');
50
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 5), 'ccccc', 5)).toEqual('T');
51
+ expect(formatter.weekday_local_stand_alone(new Date(2010, 0, 10), 'ccccc', 5)).toEqual('S');
52
+ });
53
+ });
54
+
55
+ describe("#weekday_local", function() {
56
+ it("test: pattern e", function() {
57
+ expect(formatter.weekday_local(new Date(2010, 0, 4), 'e', 1)).toEqual('1');
58
+ expect(formatter.weekday_local(new Date(2010, 0, 5), 'e', 1)).toEqual('2');
59
+ expect(formatter.weekday_local(new Date(2010, 0, 10), 'e', 1)).toEqual('7');
60
+ });
61
+
62
+ it("test: pattern ee", function() {
63
+ expect(formatter.weekday_local(new Date(2010, 0, 4), 'ee', 2)).toEqual('1');
64
+ expect(formatter.weekday_local(new Date(2010, 0, 5), 'ee', 2)).toEqual('2');
65
+ expect(formatter.weekday_local(new Date(2010, 0, 10), 'ee', 2)).toEqual('7');
66
+ });
67
+
68
+ it("test: pattern eee", function() {
69
+ expect(formatter.weekday_local(new Date(2010, 0, 4), 'eee', 3)).toEqual('Mon');
70
+ expect(formatter.weekday_local(new Date(2010, 0, 5), 'eee', 3)).toEqual('Tue');
71
+ expect(formatter.weekday_local(new Date(2010, 0, 10), 'eee', 3)).toEqual('Sun');
72
+ });
73
+
74
+ it("test: pattern eeee", function() {
75
+ expect(formatter.weekday_local(new Date(2010, 0, 4), 'eeee', 4)).toEqual('Monday');
76
+ expect(formatter.weekday_local(new Date(2010, 0, 5), 'eeee', 4)).toEqual('Tuesday');
77
+ expect(formatter.weekday_local(new Date(2010, 0, 10), 'eeee', 4)).toEqual('Sunday');
78
+ });
79
+
80
+ it("test: pattern eeeee", function() {
81
+ expect(formatter.weekday_local(new Date(2010, 0, 4), 'eeeee', 5)).toEqual('M');
82
+ expect(formatter.weekday_local(new Date(2010, 0, 5), 'eeeee', 5)).toEqual('T');
83
+ expect(formatter.weekday_local(new Date(2010, 0, 10), 'eeeee', 5)).toEqual('S');
84
+ });
85
+ });
86
+
87
+ describe("#weekday", function() {
88
+ it("test: pattern E, EE, EEE", function() {
89
+ expect(formatter.weekday(new Date(2010, 0, 1), 'E', 1)).toEqual('Fri');
90
+ expect(formatter.weekday(new Date(2010, 0, 1), 'EE', 2)).toEqual('Fri');
91
+ expect(formatter.weekday(new Date(2010, 0, 1), 'EEE', 3)).toEqual('Fri');
92
+ });
93
+
94
+ it("test: pattern EEEE", function() {
95
+ expect(formatter.weekday(new Date(2010, 0, 1), 'EEEE', 4)).toEqual('Friday');
96
+ });
97
+
98
+ it("test: pattern EEEEE", function() {
99
+ expect(formatter.weekday(new Date(2010, 0, 1), 'EEEEE', 5)).toEqual('F');
100
+ });
101
+ });
102
+
103
+ describe("#hour", function() {
104
+ it("test: h", function() {
105
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'h', 1)).toEqual('12');
106
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'h', 1)).toEqual('1');
107
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'h', 1)).toEqual('11');
108
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'h', 1)).toEqual('12');
109
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'h', 1)).toEqual('11');
110
+ });
111
+
112
+ it("test: hh", function() {
113
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'hh', 2)).toEqual('12');
114
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'hh', 2)).toEqual('01');
115
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'hh', 2)).toEqual('11');
116
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'hh', 2)).toEqual('12');
117
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'hh', 2)).toEqual('11');
118
+ });
119
+
120
+ it("test: H", function() {
121
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'H', 1)).toEqual('0');
122
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'H', 1)).toEqual('1');
123
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'H', 1)).toEqual('11');
124
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'H', 1)).toEqual('12');
125
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'H', 1)).toEqual('23');
126
+ });
127
+
128
+ it("test: HH", function() {
129
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'HH', 2)).toEqual('00');
130
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'HH', 2)).toEqual('01');
131
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'HH', 2)).toEqual('11');
132
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'HH', 2)).toEqual('12');
133
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'HH', 2)).toEqual('23');
134
+ });
135
+
136
+ it("test: K", function() {
137
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'K', 1)).toEqual('0');
138
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'K', 1)).toEqual('1');
139
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'K', 1)).toEqual('11');
140
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'K', 1)).toEqual('0');
141
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'K', 1)).toEqual('11');
142
+ });
143
+
144
+ it("test: KK", function() {
145
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'KK', 2)).toEqual('00');
146
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'KK', 2)).toEqual('01');
147
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'KK', 2)).toEqual('11');
148
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'KK', 2)).toEqual('00');
149
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'KK', 2)).toEqual('11');
150
+ });
151
+
152
+ it("test: k", function() {
153
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'k', 1)).toEqual('24');
154
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'k', 1)).toEqual('1');
155
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'k', 1)).toEqual('11');
156
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'k', 1)).toEqual('12');
157
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'k', 1)).toEqual('23');
158
+ });
159
+
160
+ it("test: kk", function() {
161
+ expect(formatter.hour(new Date(2000, 0, 1, 0, 1, 1), 'kk', 2)).toEqual('24');
162
+ expect(formatter.hour(new Date(2000, 0, 1, 1, 1, 1), 'kk', 2)).toEqual('01');
163
+ expect(formatter.hour(new Date(2000, 0, 1, 11, 1, 1), 'kk', 2)).toEqual('11');
164
+ expect(formatter.hour(new Date(2000, 0, 1, 12, 1, 1), 'kk', 2)).toEqual('12');
165
+ expect(formatter.hour(new Date(2000, 0, 1, 23, 1, 1), 'kk', 2)).toEqual('23');
166
+ });
167
+ });
168
+
169
+ describe("#minute", function() {
170
+ it("test: m", function() {
171
+ expect(formatter.minute(new Date(2000, 0, 1, 1, 1, 1), 'm', 1)).toEqual('1');
172
+ expect(formatter.minute(new Date(2000, 0, 1, 1, 11, 1), 'm', 1)).toEqual('11');
173
+ });
174
+
175
+ it("test: mm", function() {
176
+ expect(formatter.minute(new Date(2000, 0, 1, 1, 1, 1), 'mm', 2)).toEqual('01');
177
+ expect(formatter.minute(new Date(2000, 0, 1, 1, 11, 1), 'mm', 2)).toEqual('11');
178
+ });
179
+ });
180
+
181
+ // NOTE: months in JavaScript are zero-based, meaning Jan = 0, Dec = 11
182
+ describe("#month", function() {
183
+ it("test: pattern M", function() {
184
+ expect(formatter.month(new Date(2010, 0, 1), 'M', 1)).toEqual('1');
185
+ expect(formatter.month(new Date(2010, 9, 1), 'M', 1)).toEqual('10');
186
+ });
187
+
188
+ it("test: pattern MM", function() {
189
+ expect(formatter.month(new Date(2010, 0, 1), 'MM', 2)).toEqual('01');
190
+ expect(formatter.month(new Date(2010, 9, 1), 'MM', 2)).toEqual('10');
191
+ });
192
+
193
+ it("test: pattern MMM", function() {
194
+ expect(formatter.month(new Date(2010, 0, 1), 'MMM', 3)).toEqual('Jan');
195
+ expect(formatter.month(new Date(2010, 9, 1), 'MMM', 3)).toEqual('Oct');
196
+ });
197
+
198
+ it("test: pattern MMMM", function() {
199
+ expect(formatter.month(new Date(2010, 0, 1), 'MMMM', 4)).toEqual('January');
200
+ expect(formatter.month(new Date(2010, 9, 1), 'MMMM', 4)).toEqual('October');
201
+ });
202
+
203
+ it("test: pattern L", function() {
204
+ expect(formatter.month(new Date(2010, 0, 1), 'L', 1)).toEqual('1');
205
+ expect(formatter.month(new Date(2010, 9, 1), 'L', 1)).toEqual('10');
206
+ });
207
+
208
+ it("test: pattern LL", function() {
209
+ expect(formatter.month(new Date(2010, 0, 1), 'LL', 2)).toEqual('01');
210
+ expect(formatter.month(new Date(2010, 9, 1), 'LL', 2)).toEqual('10');
211
+ });
212
+ });
213
+
214
+ describe("#period", function() {
215
+ it("test: a", function() {
216
+ expect(formatter.period(new Date(2000, 0, 1, 1, 1, 1), 'a', 1)).toEqual('a.m.');
217
+ expect(formatter.period(new Date(2000, 0, 1, 15, 1, 1), 'a', 1)).toEqual('p.m.');
218
+ });
219
+ });
220
+
221
+ describe("#quarter", function() {
222
+ it("test: pattern Q", function() {
223
+ expect(formatter.quarter(new Date(2010, 0, 1), 'Q', 1)).toEqual('1');
224
+ expect(formatter.quarter(new Date(2010, 2, 31), 'Q', 1)).toEqual('1');
225
+ expect(formatter.quarter(new Date(2010, 3, 1), 'Q', 1)).toEqual('2');
226
+ expect(formatter.quarter(new Date(2010, 5, 30), 'Q', 1)).toEqual('2');
227
+ expect(formatter.quarter(new Date(2010, 6, 1), 'Q', 1)).toEqual('3');
228
+ expect(formatter.quarter(new Date(2010, 8, 30), 'Q', 1)).toEqual('3');
229
+ expect(formatter.quarter(new Date(2010, 9, 1), 'Q', 1)).toEqual('4');
230
+ expect(formatter.quarter(new Date(2010, 11, 31), 'Q', 1)).toEqual('4');
231
+ });
232
+
233
+ it("test: pattern QQ", function() {
234
+ expect(formatter.quarter(new Date(2010, 0, 1), 'QQ', 2)).toEqual('01');
235
+ expect(formatter.quarter(new Date(2010, 2, 31), 'QQ', 2)).toEqual('01');
236
+ expect(formatter.quarter(new Date(2010, 3, 1), 'QQ', 2)).toEqual('02');
237
+ expect(formatter.quarter(new Date(2010, 5, 30), 'QQ', 2)).toEqual('02');
238
+ expect(formatter.quarter(new Date(2010, 6, 1), 'QQ', 2)).toEqual('03');
239
+ expect(formatter.quarter(new Date(2010, 8, 30), 'QQ', 2)).toEqual('03');
240
+ expect(formatter.quarter(new Date(2010, 9, 1), 'QQ', 2)).toEqual('04');
241
+ expect(formatter.quarter(new Date(2010, 11, 31), 'QQ', 2)).toEqual('04');
242
+ });
243
+
244
+ it("test: pattern QQQ", function() {
245
+ expect(formatter.quarter(new Date(2010, 0, 1), 'QQQ', 3)).toEqual('Q1');
246
+ expect(formatter.quarter(new Date(2010, 2, 31), 'QQQ', 3)).toEqual('Q1');
247
+ expect(formatter.quarter(new Date(2010, 3, 1), 'QQQ', 3)).toEqual('Q2');
248
+ expect(formatter.quarter(new Date(2010, 5, 30), 'QQQ', 3)).toEqual('Q2');
249
+ expect(formatter.quarter(new Date(2010, 6, 1), 'QQQ', 3)).toEqual('Q3');
250
+ expect(formatter.quarter(new Date(2010, 8, 30), 'QQQ', 3)).toEqual('Q3');
251
+ expect(formatter.quarter(new Date(2010, 9, 1), 'QQQ', 3)).toEqual('Q4');
252
+ expect(formatter.quarter(new Date(2010, 11, 31), 'QQQ', 3)).toEqual('Q4');
253
+ });
254
+
255
+ it("test: pattern QQQQ", function() {
256
+ expect(formatter.quarter(new Date(2010, 0, 1), 'QQQQ', 4)).toEqual('1st quarter');
257
+ expect(formatter.quarter(new Date(2010, 2, 31), 'QQQQ', 4)).toEqual('1st quarter');
258
+ expect(formatter.quarter(new Date(2010, 3, 1), 'QQQQ', 4)).toEqual('2nd quarter');
259
+ expect(formatter.quarter(new Date(2010, 5, 30), 'QQQQ', 4)).toEqual('2nd quarter');
260
+ expect(formatter.quarter(new Date(2010, 6, 1), 'QQQQ', 4)).toEqual('3rd quarter');
261
+ expect(formatter.quarter(new Date(2010, 8, 30), 'QQQQ', 4)).toEqual('3rd quarter');
262
+ expect(formatter.quarter(new Date(2010, 9, 1), 'QQQQ', 4)).toEqual('4th quarter');
263
+ expect(formatter.quarter(new Date(2010, 11, 31), 'QQQQ', 4)).toEqual('4th quarter');
264
+ });
265
+
266
+ it("test: pattern q", function() {
267
+ expect(formatter.quarter(new Date(2010, 0, 1), 'q', 1)).toEqual('1');
268
+ expect(formatter.quarter(new Date(2010, 2, 31), 'q', 1)).toEqual('1');
269
+ expect(formatter.quarter(new Date(2010, 3, 1), 'q', 1)).toEqual('2');
270
+ expect(formatter.quarter(new Date(2010, 5, 30), 'q', 1)).toEqual('2');
271
+ expect(formatter.quarter(new Date(2010, 6, 1), 'q', 1)).toEqual('3');
272
+ expect(formatter.quarter(new Date(2010, 8, 30), 'q', 1)).toEqual('3');
273
+ expect(formatter.quarter(new Date(2010, 9, 1), 'q', 1)).toEqual('4');
274
+ expect(formatter.quarter(new Date(2010, 11, 31), 'q', 1)).toEqual('4');
275
+ });
276
+
277
+ it("test: pattern qq", function() {
278
+ expect(formatter.quarter(new Date(2010, 0, 1), 'qq', 2)).toEqual('01');
279
+ expect(formatter.quarter(new Date(2010, 2, 31), 'qq', 2)).toEqual('01');
280
+ expect(formatter.quarter(new Date(2010, 3, 1), 'qq', 2)).toEqual('02');
281
+ expect(formatter.quarter(new Date(2010, 5, 30), 'qq', 2)).toEqual('02');
282
+ expect(formatter.quarter(new Date(2010, 6, 1), 'qq', 2)).toEqual('03');
283
+ expect(formatter.quarter(new Date(2010, 8, 30), 'qq', 2)).toEqual('03');
284
+ expect(formatter.quarter(new Date(2010, 9, 1), 'qq', 2)).toEqual('04');
285
+ expect(formatter.quarter(new Date(2010, 11, 31), 'qq', 2)).toEqual('04');
286
+ });
287
+ });
288
+
289
+ describe("#second", function() {
290
+ it("test: s", function() {
291
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 's', 1)).toEqual('1');
292
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 11), 's', 1)).toEqual('11');
293
+ });
294
+
295
+ it("test: ss", function() {
296
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'ss', 2)).toEqual('01');
297
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 11), 'ss', 2)).toEqual('11');
298
+ });
299
+
300
+ it("test: S", function() {
301
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'S', 1)).toEqual('0');
302
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'S', 1)).toEqual('1');
303
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 18), 'S', 1)).toEqual('18');
304
+ });
305
+
306
+ it("test: SS", function() {
307
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SS', 2)).toEqual('00');
308
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SS', 2)).toEqual('01');
309
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SS', 2)).toEqual('08');
310
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SS', 2)).toEqual('21');
311
+ });
312
+
313
+ it("test: SSS", function() {
314
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SSS', 3)).toEqual('000');
315
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSS', 3)).toEqual('001');
316
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSS', 3)).toEqual('008');
317
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSS', 3)).toEqual('021');
318
+ });
319
+
320
+ it("test: SSSS", function() {
321
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 0), 'SSSS', 4)).toEqual('0000');
322
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSS', 4)).toEqual('0001');
323
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSS', 4)).toEqual('0008');
324
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSS', 4)).toEqual('0021');
325
+ });
326
+
327
+ it("test: SSSSS", function() {
328
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSSS', 5)).toEqual('00001')
329
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSSS', 5)).toEqual('00008')
330
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSSS', 5)).toEqual('00021')
331
+ });
332
+
333
+ it("test: SSSSSS", function() {
334
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 1), 'SSSSSS', 6)).toEqual('000001')
335
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 8), 'SSSSSS', 6)).toEqual('000008')
336
+ expect(formatter.second(new Date(2000, 0, 1, 1, 1, 21), 'SSSSSS', 6)).toEqual('000021')
337
+ });
338
+ });
339
+
340
+ describe("#timezone", function() {
341
+ beforeEach(function() {
342
+ date = new Date(2000, 0, 1, 1, 1, 1);
343
+ });
344
+
345
+ it("test: z, zz, zzz", function() {
346
+ expect(formatter.timezone(date, 'z', 1)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
347
+ expect(formatter.timezone(date, 'zz', 2)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
348
+ expect(formatter.timezone(date, 'zzz', 3)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
349
+ expect(formatter.timezone(date, 'zzzz', 4)).toMatch(/^UTC (-|\+)\d{2}:\d{2}$/);
350
+ });
351
+ });
352
+
353
+ // javascript handles dates differently than Ruby does, hence why this spec expects different results than it's Ruby counterpart
354
+ // eg. new Date(5, 0).getFullYear() == 1905
355
+ describe("#year", function() {
356
+ it("test: pattern y", function() {
357
+ expect(formatter.year(new Date(5, 0, 1), 'y', 1)).toEqual('1905');
358
+ expect(formatter.year(new Date(45, 0, 1), 'y', 1)).toEqual('1945');
359
+ expect(formatter.year(new Date(345, 0, 1), 'y', 1)).toEqual('345');
360
+ expect(formatter.year(new Date(2345, 0, 1), 'y', 1)).toEqual('2345');
361
+ expect(formatter.year(new Date(12345, 0, 1), 'y', 1)).toEqual('12345');
362
+ });
363
+
364
+ it("test: pattern yy", function() {
365
+ expect(formatter.year(new Date(5, 0, 1), 'yy', 2)).toEqual('05');
366
+ expect(formatter.year(new Date(45, 0, 1), 'yy', 2)).toEqual('45');
367
+ expect(formatter.year(new Date(345, 0, 1), 'yy', 2)).toEqual('45');
368
+ expect(formatter.year(new Date(2345, 0, 1), 'yy', 2)).toEqual('45');
369
+ expect(formatter.year(new Date(12345, 0, 1), 'yy', 2)).toEqual('45');
370
+ });
371
+
372
+ it("test: pattern yyy", function() {
373
+ expect(formatter.year(new Date(5, 0, 1), 'yyy', 3)).toEqual('905');
374
+ expect(formatter.year(new Date(45, 0, 1), 'yyy', 3)).toEqual('945');
375
+ expect(formatter.year(new Date(345, 0, 1), 'yyy', 3)).toEqual('345');
376
+ expect(formatter.year(new Date(2345, 0, 1), 'yyy', 3)).toEqual('345');
377
+ expect(formatter.year(new Date(12345, 0, 1), 'yyy', 3)).toEqual('345');
378
+ });
379
+
380
+ it("test: pattern yyyy", function() {
381
+ expect(formatter.year(new Date(5, 0, 1), 'yyyy', 4)).toEqual('1905');
382
+ expect(formatter.year(new Date(45, 0, 1), 'yyyy', 4)).toEqual('1945');
383
+ expect(formatter.year(new Date(345, 0, 1), 'yyyy', 4)).toEqual('0345');
384
+ expect(formatter.year(new Date(2345, 0, 1), 'yyyy', 4)).toEqual('2345');
385
+ expect(formatter.year(new Date(12345, 0, 1), 'yyyy', 4)).toEqual('2345');
386
+ });
387
+
388
+ it("test: pattern yyyyy", function() {
389
+ expect(formatter.year(new Date(5, 0, 1), 'yyyyy', 5)).toEqual('01905');
390
+ expect(formatter.year(new Date(45, 0, 1), 'yyyyy', 5)).toEqual('01945');
391
+ expect(formatter.year(new Date(345, 0, 1), 'yyyyy', 5)).toEqual('00345');
392
+ expect(formatter.year(new Date(2345, 0, 1), 'yyyyy', 5)).toEqual('02345');
393
+ expect(formatter.year(new Date(12345, 0, 1), 'yyyyy', 5)).toEqual('12345');
394
+ });
395
+ });
396
+
397
+ describe("#era", function() {
398
+ it("test: pattern G", function() {
399
+ expect(formatter.era(new Date(2012, 1, 1), 'G', 1)).toEqual("AD");
400
+ expect(formatter.era(new Date(-1, 1, 1), 'G', 1)).toEqual("BC");
401
+ });
402
+
403
+ it("test: pattern GG", function() {
404
+ expect(formatter.era(new Date(2012, 1, 1), 'GG', 2)).toEqual("AD");
405
+ expect(formatter.era(new Date(-1, 1, 1), 'GG', 2)).toEqual("BC");
406
+ });
407
+
408
+ it("test: pattern GGG", function() {
409
+ expect(formatter.era(new Date(2012, 1, 1), 'GGG', 3)).toEqual("AD");
410
+ expect(formatter.era(new Date(-1, 1, 1), 'GGG', 3)).toEqual("BC");
411
+ });
412
+
413
+ it("test: pattern GGGG", function() {
414
+ expect(formatter.era(new Date(2012, 1, 1), 'GGGG', 4)).toEqual("Anno Domini");
415
+ expect(formatter.era(new Date(-1, 1, 1), 'GGGG', 4)).toEqual("Before Christ");
416
+ });
417
+ });
418
+ });