twitter_cldr_js 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/History.txt +11 -1
- data/README.md +103 -13
- data/Rakefile +1 -1
- data/lib/assets/javascripts/twitter_cldr/af.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ar.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/be.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/bg.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/bn.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ca.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/cs.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/cy.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/da.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/de.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/el.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/en.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/es.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/eu.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/fa.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/fi.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/fil.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/fr.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ga.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/gl.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/he.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/hi.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/hu.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/id.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/it.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ja.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ko.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/lv.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/msa.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/nl.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/no.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/pl.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/pt.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ro.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ru.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/sk.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/sq.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/sr.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/sv.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ta.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/th.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/tr.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/uk.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/ur.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/zh-cn.js +1815 -0
- data/lib/assets/javascripts/twitter_cldr/zh-tw.js +1815 -0
- data/lib/twitter_cldr/js/compiler.rb +12 -3
- data/lib/twitter_cldr/js/mustache/bundle.coffee +19 -1
- data/lib/twitter_cldr/js/mustache/calendars/additional_date_format_selector.coffee +85 -0
- data/lib/twitter_cldr/js/mustache/calendars/datetime.coffee +248 -226
- data/lib/twitter_cldr/js/mustache/calendars/timespan.coffee +19 -18
- data/lib/twitter_cldr/js/mustache/numbers/numbers.coffee +62 -19
- data/lib/twitter_cldr/js/mustache/plurals/rules.coffee +1 -1
- data/lib/twitter_cldr/js/mustache/shared/bidi.coffee +433 -0
- data/lib/twitter_cldr/js/mustache/shared/calendar.coffee +25 -0
- data/lib/twitter_cldr/js/mustache/shared/currencies.coffee +5 -11
- data/lib/twitter_cldr/js/mustache/shared/lists.coffee +40 -0
- data/lib/twitter_cldr/js/mustache/shared/prerender/bidi_classes.json +1 -0
- data/lib/twitter_cldr/js/mustache/utilities.coffee +87 -0
- data/lib/twitter_cldr/js/renderers.rb +23 -19
- data/lib/twitter_cldr/js/renderers/bundle.rb +8 -2
- data/lib/twitter_cldr/js/renderers/calendars/additional_date_format_selector_renderer.rb +18 -0
- data/lib/twitter_cldr/js/renderers/calendars/datetime_renderer.rb +13 -9
- data/lib/twitter_cldr/js/renderers/numbers/numbers_renderer.rb +17 -3
- data/lib/twitter_cldr/js/renderers/shared/bidi_renderer.rb +77 -0
- data/lib/twitter_cldr/js/renderers/shared/calendar_renderer.rb +20 -0
- data/lib/twitter_cldr/js/renderers/shared/currencies_renderer.rb +2 -2
- data/lib/twitter_cldr/js/renderers/shared/list_renderer.rb +22 -0
- data/lib/twitter_cldr/js/tasks/tasks.rake +9 -5
- data/lib/twitter_cldr/js/tasks/tasks.rb +6 -5
- data/lib/twitter_cldr/js/version.rb +1 -1
- data/spec/js/calendars/additional_date_format_selector.spec.js +126 -0
- data/spec/js/calendars/datetime.spec.js +29 -2
- data/spec/js/calendars/timespan.spec.js +45 -1
- data/spec/js/numbers/abbreviated/abbreviated_number.spec.js +47 -0
- data/spec/js/numbers/abbreviated/long_decimal.spec.js +57 -0
- data/spec/js/numbers/abbreviated/short_decimal.spec.js +57 -0
- data/spec/js/numbers/currency.spec.js +2 -2
- data/spec/js/numbers/decimal.spec.js +1 -1
- data/spec/js/numbers/helpers/fraction.spec.js +1 -1
- data/spec/js/numbers/helpers/integer.spec.js +1 -1
- data/spec/js/numbers/number.spec.js +1 -1
- data/spec/js/numbers/percent.spec.js +1 -1
- data/spec/js/plurals/plural_rules.spec.js +1 -1
- data/spec/js/shared/bidi.spec.js +105 -0
- data/spec/js/shared/calendar.spec.js +51 -0
- data/spec/js/shared/classpath_bidi_test.txt +217202 -0
- data/spec/js/shared/lists.spec.js +100 -0
- data/spec/js/utilities.spec.js +120 -0
- data/twitter_cldr_js.gemspec +1 -1
- metadata +68 -37
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_af.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ar.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ca.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_cs.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_da.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_de.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_el.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_en.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_es.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_eu.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fa.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fi.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fil.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_fr.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_he.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hi.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_hu.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_id.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_it.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ja.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ko.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_msa.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_nl.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_no.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pl.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_pt.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ru.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_sv.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_th.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_tr.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_uk.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_ur.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-cn.js +0 -887
- data/lib/assets/javascripts/twitter_cldr/twitter_cldr_zh-tw.js +0 -887
@@ -11,8 +11,8 @@ module TwitterCldr
|
|
11
11
|
self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/shared/currencies.coffee"))
|
12
12
|
|
13
13
|
def currencies
|
14
|
-
TwitterCldr::Shared::Currencies.
|
15
|
-
ret[
|
14
|
+
TwitterCldr::Shared::Currencies.currency_codes.inject({}) do |ret, currency_code|
|
15
|
+
ret[currency_code] = TwitterCldr::Shared::Currencies.for_code(currency_code)
|
16
16
|
ret
|
17
17
|
end.to_json
|
18
18
|
end
|
@@ -0,0 +1,22 @@
|
|
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 Shared
|
10
|
+
|
11
|
+
class ListRenderer < TwitterCldr::Js::Renderers::Base
|
12
|
+
self.template_file = File.expand_path(File.join(File.dirname(__FILE__), "../..", "mustache/shared/lists.coffee"))
|
13
|
+
|
14
|
+
def formats
|
15
|
+
TwitterCldr.get_locale_resource(@locale, :lists)[@locale][:lists].to_json
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,11 +4,15 @@
|
|
4
4
|
# http://www.apache.org/licenses/LICENSE-2.0
|
5
5
|
|
6
6
|
namespace :twitter_cldr do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
namespace :js do
|
8
|
+
desc "Update gem's JavaScript assets"
|
9
|
+
task :update do
|
10
|
+
TwitterCldr::Js::Tasks.update
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
desc 'Compile JavaScript files (into OUTPUT_DIR or in ./twitter_cldr)'
|
14
|
+
task :compile do
|
15
|
+
TwitterCldr::Js::Tasks.compile
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
@@ -12,7 +12,7 @@ module TwitterCldr
|
|
12
12
|
build(
|
13
13
|
:begin_msg => "Updating build... ",
|
14
14
|
:output_dir => File.expand_path(File.join(File.dirname(__FILE__), "../../../assets/javascripts/twitter_cldr")),
|
15
|
-
:files => { "
|
15
|
+
:files => { "%s.js" => false }
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module TwitterCldr
|
|
20
20
|
build(
|
21
21
|
:begin_msg => "Compiling build... ",
|
22
22
|
:output_dir => get_output_dir,
|
23
|
-
:files => { "
|
23
|
+
:files => { "min/%s.min.js" => true, "full/%s.js" => false }
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
@@ -30,14 +30,15 @@ module TwitterCldr
|
|
30
30
|
locales = get_locales
|
31
31
|
$stdout.write(options[:begin_msg])
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
prerender = ENV["PRERENDER"] ? ENV["PRERENDER"] == "true" : nil
|
34
|
+
compiler = TwitterCldr::Js::Compiler.new(:locales => locales, :prerender => prerender)
|
35
|
+
output_dir = File.expand_path(options[:output_dir] || get_output_dir)
|
35
36
|
|
36
37
|
build_duration = time_operation do
|
37
38
|
options[:files].each_pair do |file_pattern, minify|
|
38
39
|
compiler.compile_each(:minify => minify) do |bundle, locale|
|
39
40
|
out_file = File.join(output_dir, file_pattern % locale)
|
40
|
-
FileUtils.mkdir_p(File.
|
41
|
+
FileUtils.mkdir_p(File.dirname(out_file))
|
41
42
|
File.open(out_file, "w+") do |f|
|
42
43
|
f.write(bundle)
|
43
44
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/en.js');
|
5
|
+
|
6
|
+
describe("AdditionalDateFormatSelector", function() {
|
7
|
+
beforeEach(function() {
|
8
|
+
selector = new TwitterCldr.AdditionalDateFormatSelector(
|
9
|
+
TwitterCldr.Calendar.calendar.additional_formats
|
10
|
+
)
|
11
|
+
});
|
12
|
+
|
13
|
+
describe("#position_score", function() {
|
14
|
+
it("calculates the score based on relative offset from actual position", function() {
|
15
|
+
var goal_entities = selector.separate("MMMyyd");
|
16
|
+
var entities = selector.separate("d");
|
17
|
+
expect(selector.position_score(entities, goal_entities)).toEqual(2);
|
18
|
+
});
|
19
|
+
|
20
|
+
it("calculates a zero score if all entites are in the same positions", function() {
|
21
|
+
var goal_entities = selector.separate("MMMyyd");
|
22
|
+
var entities = selector.separate("MMMyyd");
|
23
|
+
expect(selector.position_score(entities, goal_entities)).toEqual(0);
|
24
|
+
});
|
25
|
+
});
|
26
|
+
|
27
|
+
describe("#exist_score", function() {
|
28
|
+
it("calculates a higher score if an entity doesn't exist", function() {
|
29
|
+
var goal_entities = selector.separate("MMMd");
|
30
|
+
var entities = selector.separate("d");
|
31
|
+
expect(selector.exist_score(entities, goal_entities)).toEqual(1);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("calculates a zero score if all entities exist", function() {
|
35
|
+
var goal_entities = selector.separate("MMMyyd");
|
36
|
+
var entities = selector.separate("dMMMyy");
|
37
|
+
expect(selector.exist_score(entities, goal_entities)).toEqual(0);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
describe("#count_score", function() {
|
42
|
+
it("calculates the score based on the difference in the length of each matching entity", function() {
|
43
|
+
var goal_entities = selector.separate("MMMyyd");
|
44
|
+
var entities = selector.separate("ddMMy");
|
45
|
+
expect(selector.count_score(entities, goal_entities)).toEqual(3);
|
46
|
+
});
|
47
|
+
|
48
|
+
it("calculates a zero score if all entities are the same length", function() {
|
49
|
+
var goal_entities = selector.separate("MMMyyd");
|
50
|
+
var entities = selector.separate("d");
|
51
|
+
expect(selector.count_score(entities, goal_entities)).toEqual(0);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
describe("#score", function() {
|
56
|
+
it("calculates a cumulative score from position and count", function() {
|
57
|
+
var goal_entities = selector.separate("MMMyydGG");
|
58
|
+
var entities = selector.separate("ddMMGGyy");
|
59
|
+
expect(selector.exist_score(entities, goal_entities)).toEqual(0);
|
60
|
+
expect(selector.count_score(entities, goal_entities)).toEqual(2);
|
61
|
+
expect(selector.position_score(entities, goal_entities)).toEqual(3);
|
62
|
+
expect(selector.score(entities, goal_entities)).toEqual(5);
|
63
|
+
});
|
64
|
+
|
65
|
+
it("calculates a cumulative score from position, count, and existence (existence weighted by 2)", function() {
|
66
|
+
var goal_entities = selector.separate("MMMyydGG");
|
67
|
+
var entities = selector.separate("ddMMyy");
|
68
|
+
expect(selector.exist_score(entities, goal_entities)).toEqual(1);
|
69
|
+
expect(selector.count_score(entities, goal_entities)).toEqual(2);
|
70
|
+
expect(selector.position_score(entities, goal_entities)).toEqual(1);
|
71
|
+
// (exist_score * 2) + count_score + position_score
|
72
|
+
expect(selector.score(entities, goal_entities)).toEqual(5);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
describe("#rank", function() {
|
77
|
+
it("returns a score for each available format", function() {
|
78
|
+
var ranked_formats = selector.rank("MMMd");
|
79
|
+
expect(ranked_formats["MMMd"]).toEqual(0);
|
80
|
+
expect(ranked_formats["yMEd"]).toEqual(4);
|
81
|
+
expect(ranked_formats["y"]).toEqual(4);
|
82
|
+
expect(ranked_formats["EHms"]).toEqual(4);
|
83
|
+
expect(ranked_formats["MMM"]).toEqual(2);
|
84
|
+
});
|
85
|
+
});
|
86
|
+
|
87
|
+
describe("#find_closest", function() {
|
88
|
+
it("returns an exact match if it exists", function() {
|
89
|
+
expect(selector.find_closest("MMMd")).toEqual("MMMd");
|
90
|
+
expect(selector.find_closest("Hms")).toEqual("Hms");
|
91
|
+
expect(selector.find_closest("yQQQQ")).toEqual("yQQQQ");
|
92
|
+
});
|
93
|
+
|
94
|
+
it("returns the next closest match (lowest score) if an exact match can't be found", function() {
|
95
|
+
expect(selector.find_closest("MMMMd")).toEqual("MMMd");
|
96
|
+
expect(selector.find_closest("mHs")).toEqual("Hms");
|
97
|
+
expect(selector.find_closest("Ehds")).toEqual("Ehms");
|
98
|
+
});
|
99
|
+
|
100
|
+
it("returns nil if an empty pattern is given", function() {
|
101
|
+
expect(selector.find_closest(null)).toBeNull();
|
102
|
+
expect(selector.find_closest("")).toBeNull();
|
103
|
+
expect(selector.find_closest(" ")).toBeNull();
|
104
|
+
});
|
105
|
+
});
|
106
|
+
|
107
|
+
describe("#separate", function() {
|
108
|
+
it("divides a string into entities by runs of equal characters", function() {
|
109
|
+
expect(selector.separate("ddMMyy")).toEqual(["dd", "MM", "yy"]);
|
110
|
+
expect(selector.separate("ddMMyyMM")).toEqual(["dd", "MM", "yy", "MM"]);
|
111
|
+
expect(selector.separate("mmMM")).toEqual(["mm", "MM"]);
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
describe("#patterns", function() {
|
116
|
+
it("returns a list of all available patterns", function() {
|
117
|
+
var patterns = selector.patterns();
|
118
|
+
expect(patterns.constructor.name).toEqual("Array")
|
119
|
+
expect(patterns.indexOf("MMMd")).toBeGreaterThan(-1);
|
120
|
+
expect(patterns.indexOf("yQQQ")).toBeGreaterThan(-1);
|
121
|
+
expect(patterns.indexOf("yQQQQ")).toBeGreaterThan(-1);
|
122
|
+
expect(patterns.indexOf("EHms")).toBeGreaterThan(-1);
|
123
|
+
expect(patterns.indexOf("d")).toBeGreaterThan(-1);
|
124
|
+
});
|
125
|
+
});
|
126
|
+
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// Copyright 2012 Twitter, Inc
|
2
2
|
// http://www.apache.org/licenses/LICENSE-2.0
|
3
3
|
|
4
|
-
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/en.js');
|
5
5
|
|
6
6
|
describe("DateTimeFormatter", function() {
|
7
7
|
beforeEach(function() {
|
@@ -346,7 +346,7 @@ describe("DateTimeFormatter", function() {
|
|
346
346
|
expect(formatter.timezone(date, 'z', 1)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
|
347
347
|
expect(formatter.timezone(date, 'zz', 2)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
|
348
348
|
expect(formatter.timezone(date, 'zzz', 3)).toMatch(/^(-|\+)\d{2}:\d{2}$/);
|
349
|
-
expect(formatter.timezone(date, 'zzzz', 4)).toMatch(/^UTC
|
349
|
+
expect(formatter.timezone(date, 'zzzz', 4)).toMatch(/^UTC(-|\+)\d{2}:\d{2}$/);
|
350
350
|
});
|
351
351
|
});
|
352
352
|
|
@@ -414,5 +414,32 @@ describe("DateTimeFormatter", function() {
|
|
414
414
|
expect(formatter.era(new Date(2012, 1, 1), 'GGGG', 4)).toEqual("Anno Domini");
|
415
415
|
expect(formatter.era(new Date(-1, 1, 1), 'GGGG', 4)).toEqual("Before Christ");
|
416
416
|
});
|
417
|
+
|
418
|
+
it("should fall back if the calendar doesn't contain the appropriate era data", function() {
|
419
|
+
old_era_data = TwitterCldr.Calendar.calendar.eras;
|
420
|
+
TwitterCldr.Calendar.calendar.eras = {
|
421
|
+
abbr: {
|
422
|
+
0: "abbr0",
|
423
|
+
1: "abbr1"
|
424
|
+
},
|
425
|
+
name: {
|
426
|
+
0: "name0"
|
427
|
+
}
|
428
|
+
};
|
429
|
+
|
430
|
+
date = new Date(2012, 1, 1);
|
431
|
+
expect(formatter.era(date, 'GGGG', 4)).toEqual("abbr1");
|
432
|
+
TwitterCldr.Calendar.calendar.eras = old_era_data;
|
433
|
+
});
|
434
|
+
});
|
435
|
+
|
436
|
+
describe("#format", function() {
|
437
|
+
it("don't raise errors for additional date formats", function() {
|
438
|
+
var patterns = formatter.additional_format_selector().patterns();
|
439
|
+
for (key in patterns) {
|
440
|
+
// these shouldn't raise errors
|
441
|
+
formatter.format(new Date(), {format: "additional", type: patterns[key]});
|
442
|
+
}
|
443
|
+
});
|
417
444
|
});
|
418
445
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// Copyright 2012 Twitter, Inc
|
2
2
|
// http://www.apache.org/licenses/LICENSE-2.0
|
3
3
|
|
4
|
-
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/
|
4
|
+
var TwitterCldr = require('../../../lib/assets/javascripts/twitter_cldr/en.js');
|
5
5
|
|
6
6
|
describe("TimespanFormatter", function() {
|
7
7
|
beforeEach(function() {
|
@@ -9,6 +9,50 @@ describe("TimespanFormatter", function() {
|
|
9
9
|
});
|
10
10
|
|
11
11
|
describe("#format", function() {
|
12
|
+
it("approximates timespans accurately if explicity asked to", function() {
|
13
|
+
var options = {direction: "none", approximate: true}
|
14
|
+
expect(formatter.format(44, options)).toEqual("44 seconds");
|
15
|
+
expect(formatter.format(45, options)).toEqual("1 minute");
|
16
|
+
|
17
|
+
expect(formatter.format(2699, options)).toEqual("45 minutes");
|
18
|
+
expect(formatter.format(2700, options)).toEqual("1 hour");
|
19
|
+
|
20
|
+
expect(formatter.format(64799, options)).toEqual("18 hours");
|
21
|
+
expect(formatter.format(64800, options)).toEqual("1 day");
|
22
|
+
|
23
|
+
expect(formatter.format(453599, options)).toEqual("5 days");
|
24
|
+
expect(formatter.format(453600, options)).toEqual("1 week");
|
25
|
+
|
26
|
+
expect(formatter.format(1972307, options)).toEqual("3 weeks");
|
27
|
+
expect(formatter.format(1972308, options)).toEqual("1 month");
|
28
|
+
|
29
|
+
expect(formatter.format(23667694, options)).toEqual("9 months");
|
30
|
+
expect(formatter.format(23667695, options)).toEqual("1 year");
|
31
|
+
});
|
32
|
+
|
33
|
+
it("doesn't approximate timespans by default", function() {
|
34
|
+
var options = {direction: "none"}
|
35
|
+
expect(formatter.format(44, options)).toEqual("44 seconds");
|
36
|
+
expect(formatter.format(45, options)).toEqual("45 seconds");
|
37
|
+
|
38
|
+
expect(formatter.format(2699, options)).toEqual("45 minutes");
|
39
|
+
expect(formatter.format(2700, options)).toEqual("45 minutes");
|
40
|
+
|
41
|
+
expect(formatter.format(64799, options)).toEqual("18 hours");
|
42
|
+
expect(formatter.format(64800, options)).toEqual("18 hours");
|
43
|
+
|
44
|
+
expect(formatter.format(453599, options)).toEqual("5 days");
|
45
|
+
expect(formatter.format(453600, options)).toEqual("5 days");
|
46
|
+
|
47
|
+
expect(formatter.format(1972307, options)).toEqual("3 weeks");
|
48
|
+
expect(formatter.format(1972308, options)).toEqual("3 weeks");
|
49
|
+
|
50
|
+
expect(formatter.format(23667694, options)).toEqual("9 months");
|
51
|
+
expect(formatter.format(23667695, options)).toEqual("9 months");
|
52
|
+
|
53
|
+
expect(formatter.format(31556926, options)).toEqual("1 year");
|
54
|
+
});
|
55
|
+
|
12
56
|
it("works for a variety of units for a non-directional timespan", function() {
|
13
57
|
expect(formatter.format(3273932, {
|
14
58
|
unit: "year",
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../../lib/assets/javascripts/twitter_cldr/en.js');
|
5
|
+
|
6
|
+
describe("AbbreviatedNumberFormatter", function() {
|
7
|
+
beforeEach(function() {
|
8
|
+
formatter = new TwitterCldr.AbbreviatedNumberFormatter();
|
9
|
+
});
|
10
|
+
|
11
|
+
describe("#transform_number", function() {
|
12
|
+
it("chops off the number to the necessary number of sig figs", function() {
|
13
|
+
expect(formatter.transform_number(Math.pow(10, 3))).toEqual(1);
|
14
|
+
expect(formatter.transform_number(Math.pow(10, 4))).toEqual(10);
|
15
|
+
expect(formatter.transform_number(Math.pow(10, 5))).toEqual(100);
|
16
|
+
expect(formatter.transform_number(Math.pow(10, 6))).toEqual(1);
|
17
|
+
expect(formatter.transform_number(Math.pow(10, 7))).toEqual(10);
|
18
|
+
expect(formatter.transform_number(Math.pow(10, 8))).toEqual(100);
|
19
|
+
expect(formatter.transform_number(Math.pow(10, 9))).toEqual(1);
|
20
|
+
expect(formatter.transform_number(Math.pow(10, 10))).toEqual(10);
|
21
|
+
expect(formatter.transform_number(Math.pow(10, 11))).toEqual(100);
|
22
|
+
expect(formatter.transform_number(Math.pow(10, 12))).toEqual(1);
|
23
|
+
expect(formatter.transform_number(Math.pow(10, 13))).toEqual(10);
|
24
|
+
expect(formatter.transform_number(Math.pow(10, 14))).toEqual(100);
|
25
|
+
});
|
26
|
+
|
27
|
+
it("returns the original number if greater than 10^15", function() {
|
28
|
+
expect(formatter.transform_number(Math.pow(10, 15))).toEqual(Math.pow(10, 15));
|
29
|
+
});
|
30
|
+
|
31
|
+
it("returns the original number if less than 10^3", function() {
|
32
|
+
expect(formatter.transform_number(999)).toEqual(999);
|
33
|
+
});
|
34
|
+
});
|
35
|
+
|
36
|
+
describe("#get_key", function() {
|
37
|
+
it("builds a power-of-ten key based on the number of digits in the input", function() {
|
38
|
+
for(var i = 3; i < 15; i ++) {
|
39
|
+
var zeroes = "";
|
40
|
+
for(var j = 0; j < (i - 3); j ++) {
|
41
|
+
zeroes += "0";
|
42
|
+
}
|
43
|
+
expect(formatter.get_key(parseInt("1337" + zeroes))).toEqual(Math.pow(10, i).toString());
|
44
|
+
}
|
45
|
+
});
|
46
|
+
});
|
47
|
+
});
|
@@ -0,0 +1,57 @@
|
|
1
|
+
// Copyright 2012 Twitter, Inc
|
2
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
var TwitterCldr = require('../../../../lib/assets/javascripts/twitter_cldr/en.js');
|
5
|
+
|
6
|
+
describe("LongDecimalFormatter", function() {
|
7
|
+
beforeEach(function() {
|
8
|
+
formatter = new TwitterCldr.LongDecimalFormatter();
|
9
|
+
});
|
10
|
+
|
11
|
+
describe("#get_tokens", function() {
|
12
|
+
it("gets tokens for a valid number (between 10^3 and 10^15)", function() {
|
13
|
+
expect(formatter.get_tokens(12345)).toEqual(formatter.all_tokens.long_decimal.positive[10000]);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("returns tokens for decimals if the number is too large", function() {
|
17
|
+
expect(formatter.get_tokens(1234567891011122)).toEqual(formatter.all_tokens.decimal.positive);
|
18
|
+
});
|
19
|
+
|
20
|
+
it("returns tokens for decimals if the number is too small", function() {
|
21
|
+
expect(formatter.get_tokens(123)).toEqual(formatter.all_tokens.decimal.positive);
|
22
|
+
});
|
23
|
+
});
|
24
|
+
|
25
|
+
describe("#format", function() {
|
26
|
+
it("should default to a precision of 0", function() {
|
27
|
+
expect(formatter.format(1000)).toEqual("1 thousand");
|
28
|
+
});
|
29
|
+
|
30
|
+
it("should not overwrite precision when explicitly passed", function() {
|
31
|
+
expect(formatter.format(1000, {precision: 1})).toEqual("1.0 thousand");
|
32
|
+
});
|
33
|
+
|
34
|
+
it("formats valid numbers correctly (from 10^3 - 10^15)", function() {
|
35
|
+
expect(formatter.format(Math.pow(10, 3))).toEqual("1 thousand");
|
36
|
+
expect(formatter.format(Math.pow(10, 4))).toEqual("10 thousand");
|
37
|
+
expect(formatter.format(Math.pow(10, 5))).toEqual("100 thousand");
|
38
|
+
expect(formatter.format(Math.pow(10, 6))).toEqual("1 million");
|
39
|
+
expect(formatter.format(Math.pow(10, 7))).toEqual("10 million");
|
40
|
+
expect(formatter.format(Math.pow(10, 8))).toEqual("100 million");
|
41
|
+
expect(formatter.format(Math.pow(10, 9))).toEqual("1 billion");
|
42
|
+
expect(formatter.format(Math.pow(10, 10))).toEqual("10 billion");
|
43
|
+
expect(formatter.format(Math.pow(10, 11))).toEqual("100 billion");
|
44
|
+
expect(formatter.format(Math.pow(10, 12))).toEqual("1 trillion");
|
45
|
+
expect(formatter.format(Math.pow(10, 13))).toEqual("10 trillion");
|
46
|
+
expect(formatter.format(Math.pow(10, 14))).toEqual("100 trillion");
|
47
|
+
});
|
48
|
+
|
49
|
+
it("formats the number as if it were a straight decimal if it exceeds 10^15", function() {
|
50
|
+
expect(formatter.format(Math.pow(10, 15))).toEqual("1,000,000,000,000,000");
|
51
|
+
});
|
52
|
+
|
53
|
+
it("formats the number as if it were a straight decimal if it's less than 1000", function() {
|
54
|
+
expect(formatter.format(500)).toEqual("500");
|
55
|
+
});
|
56
|
+
});
|
57
|
+
});
|