twitter_cldr_js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +12 -0
- data/History.txt +3 -0
- data/LICENSE +177 -0
- data/NOTICE +120 -0
- data/README.md +161 -0
- data/Rakefile +66 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_af.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ar.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ca.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_cs.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_da.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_de.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_el.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_es.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_eu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fil.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_he.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hi.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hu.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_id.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_it.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ja.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ko.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_msa.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_nl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_no.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pl.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pt.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ru.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_sv.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_th.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_tr.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_uk.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ur.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-cn.js +887 -0
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-tw.js +887 -0
- data/lib/twitter_cldr/js/compiler.rb +49 -0
- data/lib/twitter_cldr/js/mustache/bundle.coffee +15 -0
- data/lib/twitter_cldr/js/mustache/calendars/datetime.coffee +240 -0
- data/lib/twitter_cldr/js/mustache/calendars/timespan.coffee +52 -0
- data/lib/twitter_cldr/js/mustache/numbers/numbers.coffee +179 -0
- data/lib/twitter_cldr/js/mustache/plurals/rules.coffee +14 -0
- data/lib/twitter_cldr/js/mustache/shared/currencies.coffee +27 -0
- data/lib/twitter_cldr/js/renderers/base.rb +18 -0
- data/lib/twitter_cldr/js/renderers/bundle.rb +18 -0
- data/lib/twitter_cldr/js/renderers/calendars/datetime_renderer.rb +34 -0
- data/lib/twitter_cldr/js/renderers/calendars/timespan_renderer.rb +39 -0
- data/lib/twitter_cldr/js/renderers/numbers/numbers_renderer.rb +31 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_compiler.rb +93 -0
- data/lib/twitter_cldr/js/renderers/plurals/rules/plural_rules_renderer.rb +26 -0
- data/lib/twitter_cldr/js/renderers/shared/currencies_renderer.rb +23 -0
- data/lib/twitter_cldr/js/renderers.rb +31 -0
- data/lib/twitter_cldr/js/tasks/tasks.rake +14 -0
- data/lib/twitter_cldr/js/tasks/tasks.rb +88 -0
- data/lib/twitter_cldr/js/version.rb +10 -0
- data/lib/twitter_cldr/js.rb +31 -0
- data/spec/js/calendars/datetime.spec.js +418 -0
- data/spec/js/calendars/timespan.spec.js +91 -0
- data/spec/js/numbers/currency.spec.js +34 -0
- data/spec/js/numbers/decimal.spec.js +24 -0
- data/spec/js/numbers/helpers/fraction.spec.js +23 -0
- data/spec/js/numbers/helpers/integer.spec.js +100 -0
- data/spec/js/numbers/number.spec.js +70 -0
- data/spec/js/numbers/percent.spec.js +22 -0
- data/spec/js/plurals/plural_rules.spec.js +28 -0
- data/spec/ruby/renderers/plurals/plural_rules_compiler_spec.rb +56 -0
- data/spec/ruby/spec_helper.rb +11 -0
- data/twitter_cldr_js.gemspec +34 -0
- metadata +224 -0
@@ -0,0 +1,418 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/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
|
+
});
|
@@ -0,0 +1,91 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js');
|
5
|
+
|
6
|
+
describe("TimespanFormatter", function() {
|
7
|
+
beforeEach(function() {
|
8
|
+
formatter = new TwitterCldr.TimespanFormatter();
|
9
|
+
});
|
10
|
+
|
11
|
+
describe("#format", function() {
|
12
|
+
it("works for a variety of units for a non-directional timespan", function() {
|
13
|
+
expect(formatter.format(3273932, {
|
14
|
+
unit: "year",
|
15
|
+
direction: "none"
|
16
|
+
})).toEqual('0 years');
|
17
|
+
expect(formatter.format(3273932, {
|
18
|
+
unit: "month",
|
19
|
+
direction: "none",
|
20
|
+
})).toEqual('1 month');
|
21
|
+
expect(formatter.format(3273932, {
|
22
|
+
unit: "week",
|
23
|
+
direction: "none"
|
24
|
+
})).toEqual('5 weeks');
|
25
|
+
expect(formatter.format(3273932, {
|
26
|
+
unit: "day",
|
27
|
+
direction: "none"
|
28
|
+
})).toEqual('38 days');
|
29
|
+
expect(formatter.format(3273932, {
|
30
|
+
unit: "hour",
|
31
|
+
direction: "none"
|
32
|
+
})).toEqual('909 hours');
|
33
|
+
expect(formatter.format(3273932, {
|
34
|
+
unit: "minute",
|
35
|
+
direction: "none"
|
36
|
+
})).toEqual('54566 minutes');
|
37
|
+
expect(formatter.format(3273932, {
|
38
|
+
unit: "second",
|
39
|
+
direction: "none"
|
40
|
+
})).toEqual('3273932 seconds');
|
41
|
+
});
|
42
|
+
|
43
|
+
it("works for a variety of units in the past", function() {
|
44
|
+
expect(formatter.format(-3273932, {
|
45
|
+
unit: "year"
|
46
|
+
})).toEqual('0 years ago');
|
47
|
+
expect(formatter.format(-3273932, {
|
48
|
+
unit: "month"
|
49
|
+
})).toEqual('1 month ago');
|
50
|
+
expect(formatter.format(-3273932, {
|
51
|
+
unit: "week"
|
52
|
+
})).toEqual('5 weeks ago');
|
53
|
+
expect(formatter.format(-3273932, {
|
54
|
+
unit: "day"
|
55
|
+
})).toEqual('38 days ago');
|
56
|
+
expect(formatter.format(-3273932, {
|
57
|
+
unit: "hour"
|
58
|
+
})).toEqual('909 hours ago');
|
59
|
+
expect(formatter.format(-3273932, {
|
60
|
+
unit: "minute"
|
61
|
+
})).toEqual('54566 minutes ago');
|
62
|
+
expect(formatter.format(-3273932, {
|
63
|
+
unit: "second"
|
64
|
+
})).toEqual('3273932 seconds ago');
|
65
|
+
});
|
66
|
+
|
67
|
+
it("works for a variety of units in the future", function() {
|
68
|
+
expect(formatter.format(3273932, {
|
69
|
+
unit: "year"
|
70
|
+
})).toEqual('In 0 years');
|
71
|
+
expect(formatter.format(3273932, {
|
72
|
+
unit: "month"
|
73
|
+
})).toEqual('In 1 month');
|
74
|
+
expect(formatter.format(3273932, {
|
75
|
+
unit: "week"
|
76
|
+
})).toEqual('In 5 weeks');
|
77
|
+
expect(formatter.format(3273932, {
|
78
|
+
unit: "day"
|
79
|
+
})).toEqual('In 38 days');
|
80
|
+
expect(formatter.format(3273932, {
|
81
|
+
unit: "hour"
|
82
|
+
})).toEqual('In 909 hours');
|
83
|
+
expect(formatter.format(3273932, {
|
84
|
+
unit: "minute"
|
85
|
+
})).toEqual('In 54566 minutes');
|
86
|
+
expect(formatter.format(3273932, {
|
87
|
+
unit: "second"
|
88
|
+
})).toEqual('In 3273932 seconds');
|
89
|
+
});
|
90
|
+
});
|
91
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js');
|
5
|
+
|
6
|
+
describe("CurrencyFormatter", function() {
|
7
|
+
describe("#format", function() {
|
8
|
+
beforeEach(function() {
|
9
|
+
formatter = new TwitterCldr.CurrencyFormatter();
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should use a dollar sign when no other currency symbol is given (and default to a precision of 2)", function() {
|
13
|
+
expect(formatter.format(12)).toEqual("$12.00");
|
14
|
+
});
|
15
|
+
|
16
|
+
it("handles negative numbers", function() {
|
17
|
+
// yes, the parentheses really are part of the format, don't worry about it
|
18
|
+
expect(formatter.format(-12)).toEqual("-($12.00)");
|
19
|
+
});
|
20
|
+
|
21
|
+
it("should use the specified currency symbol when specified", function() {
|
22
|
+
// S/. is the symbol for the Peruvian Nuevo Sol, just in case you were curious
|
23
|
+
expect(formatter.format(12, {currency: "S/."})).toEqual("S/.12.00");
|
24
|
+
});
|
25
|
+
|
26
|
+
it("should use the currency symbol for the corresponding currency code", function() {
|
27
|
+
expect(formatter.format(12, {currency: "PEN"})).toEqual("S/.12.00");
|
28
|
+
});
|
29
|
+
|
30
|
+
it("overrides the default precision", function() {
|
31
|
+
expect(formatter.format(12, {precision: 3})).toEqual("$12.000");
|
32
|
+
});
|
33
|
+
});
|
34
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js');
|
5
|
+
|
6
|
+
describe("DecimalFormatter", function() {
|
7
|
+
beforeEach(function() {
|
8
|
+
formatter = new TwitterCldr.DecimalFormatter();
|
9
|
+
});
|
10
|
+
|
11
|
+
describe("#format", function() {
|
12
|
+
it("should format positive decimals correctly", function() {
|
13
|
+
expect(formatter.format(12.1)).toEqual("12.1");
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should format negative decimals correctly", function() {
|
17
|
+
expect(formatter.format(-12.1)).toEqual("-12.1");
|
18
|
+
});
|
19
|
+
|
20
|
+
it("should respect the precision option", function() {
|
21
|
+
expect(formatter.format(-12, {precision: 3})).toEqual("-12.000");
|
22
|
+
});
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../../lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js');
|
5
|
+
|
6
|
+
describe("FractionHelper", function() {
|
7
|
+
describe("#apply", function() {
|
8
|
+
it("test: formats a fraction", function() {
|
9
|
+
var token = '###.##';
|
10
|
+
expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('45')).toEqual('.45');
|
11
|
+
});
|
12
|
+
|
13
|
+
it("test: pads zero digits on the right side", function() {
|
14
|
+
var token = '###.0000#';
|
15
|
+
expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('45')).toEqual('.45000');
|
16
|
+
});
|
17
|
+
|
18
|
+
it("test: :precision option overrides format precision", function() {
|
19
|
+
var token = '###.##';
|
20
|
+
expect(new TwitterCldr.NumberFormatter.FractionHelper(token).apply('78901', {precision: 5})).toEqual('.78901');
|
21
|
+
});
|
22
|
+
});
|
23
|
+
});
|