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,6 +11,7 @@ module TwitterCldr
|
|
11
11
|
def initialize(options = {})
|
12
12
|
@locales = options[:locales] || TwitterCldr.supported_locales
|
13
13
|
@features = options[:features] || renderers.keys
|
14
|
+
@prerender = options[:prerender].nil? ? true : options[:prerender]
|
14
15
|
end
|
15
16
|
|
16
17
|
def compile_each(options = {})
|
@@ -21,12 +22,16 @@ module TwitterCldr
|
|
21
22
|
|
22
23
|
@features.each do |feature|
|
23
24
|
renderer_const = renderers[feature]
|
24
|
-
contents << renderer_const.new(:locale => locale).render if renderer_const
|
25
|
+
contents << renderer_const.new(:locale => locale, :prerender => @prerender).render if renderer_const
|
25
26
|
end
|
26
27
|
|
27
28
|
bundle = TwitterCldr::Js::Renderers::Bundle.new
|
29
|
+
bundle[:locale] = locale
|
28
30
|
bundle[:contents] = contents
|
29
|
-
result = CoffeeScript.compile(bundle.render, :bare =>
|
31
|
+
result = CoffeeScript.compile(bundle.render, :bare => false)
|
32
|
+
|
33
|
+
# required alias definition that adds twitter_cldr to Twitter's static build process
|
34
|
+
result.gsub!(/\/\*<<module_def>>\s+\*\//, %Q(/*-module-*/\n/*_lib/twitter_cldr_*/))
|
30
35
|
result = Uglifier.compile(result) if options[:minify]
|
31
36
|
|
32
37
|
yield result, TwitterCldr.twitter_locale(locale)
|
@@ -40,8 +45,12 @@ module TwitterCldr
|
|
40
45
|
:plural_rules => TwitterCldr::Js::Renderers::PluralRules::PluralRulesRenderer,
|
41
46
|
:timespan => TwitterCldr::Js::Renderers::Calendars::TimespanRenderer,
|
42
47
|
:datetime => TwitterCldr::Js::Renderers::Calendars::DateTimeRenderer,
|
48
|
+
:additional_date_format_selector => TwitterCldr::Js::Renderers::Calendars::AdditionalDateFormatSelectorRenderer,
|
43
49
|
:numbers => TwitterCldr::Js::Renderers::Numbers::NumbersRenderer,
|
44
|
-
:currencies => TwitterCldr::Js::Renderers::Shared::CurrenciesRenderer
|
50
|
+
:currencies => TwitterCldr::Js::Renderers::Shared::CurrenciesRenderer,
|
51
|
+
:lists => TwitterCldr::Js::Renderers::Shared::ListRenderer,
|
52
|
+
:bidi => TwitterCldr::Js::Renderers::Shared::BidiRenderer,
|
53
|
+
:calendar => TwitterCldr::Js::Renderers::Shared::CalendarRenderer
|
45
54
|
}
|
46
55
|
end
|
47
56
|
end
|
@@ -10,6 +10,24 @@
|
|
10
10
|
// Description: Provides date, time, number, and list formatting functionality for various Twitter-supported locales in Javascript.
|
11
11
|
###
|
12
12
|
|
13
|
+
# required alias definition that adds twitter_cldr to Twitter's static build process
|
14
|
+
###<<module_def>>###
|
15
|
+
|
13
16
|
TwitterCldr = {}
|
17
|
+
{{#is_rtl?}}
|
18
|
+
TwitterCldr.is_rtl = true;
|
19
|
+
{{/is_rtl?}}
|
20
|
+
{{^is_rtl?}}
|
21
|
+
TwitterCldr.is_rtl = false;
|
22
|
+
{{/is_rtl?}}
|
23
|
+
|
24
|
+
{{> utilities}}
|
14
25
|
{{{contents}}}
|
15
|
-
|
26
|
+
|
27
|
+
root = if exports?
|
28
|
+
exports
|
29
|
+
else
|
30
|
+
this.TwitterCldr = {}
|
31
|
+
this.TwitterCldr
|
32
|
+
|
33
|
+
root[key] = obj for key, obj of TwitterCldr
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Copyright 2012 Twitter, Inc
|
2
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
3
|
+
|
4
|
+
class TwitterCldr.AdditionalDateFormatSelector
|
5
|
+
constructor: (pattern_hash) ->
|
6
|
+
@pattern_hash = pattern_hash
|
7
|
+
|
8
|
+
find_closest: (goal_pattern) ->
|
9
|
+
if !goal_pattern? || goal_pattern.trim().length == 0
|
10
|
+
null
|
11
|
+
else
|
12
|
+
ranks = this.rank(goal_pattern)
|
13
|
+
min_rank = 100
|
14
|
+
min_key = null
|
15
|
+
|
16
|
+
for key, rank of ranks
|
17
|
+
if rank < min_rank
|
18
|
+
min_rank = rank
|
19
|
+
min_key = key
|
20
|
+
|
21
|
+
min_key
|
22
|
+
|
23
|
+
patterns: ->
|
24
|
+
key for key of @pattern_hash
|
25
|
+
|
26
|
+
separate: (pattern_key) ->
|
27
|
+
last_char = ""
|
28
|
+
result = []
|
29
|
+
|
30
|
+
for cur_char in pattern_key
|
31
|
+
if cur_char == last_char
|
32
|
+
result[result.length - 1] += cur_char
|
33
|
+
else
|
34
|
+
result.push(cur_char)
|
35
|
+
|
36
|
+
last_char = cur_char
|
37
|
+
|
38
|
+
result
|
39
|
+
|
40
|
+
all_separated_patterns: ->
|
41
|
+
this.separate(key) for key of @pattern_hash
|
42
|
+
|
43
|
+
score: (entities, goal_entities) ->
|
44
|
+
# weight existence a little more heavily than the others
|
45
|
+
score = this.exist_score(entities, goal_entities) * 2
|
46
|
+
score += this.position_score(entities, goal_entities)
|
47
|
+
score + this.count_score(entities, goal_entities)
|
48
|
+
|
49
|
+
position_score: (entities, goal_entities) ->
|
50
|
+
sum = 0
|
51
|
+
|
52
|
+
for index, goal_entity of goal_entities
|
53
|
+
found = entities.indexOf(goal_entity)
|
54
|
+
if found > -1
|
55
|
+
sum += Math.abs(found - index)
|
56
|
+
|
57
|
+
sum
|
58
|
+
|
59
|
+
exist_score: (entities, goal_entities) ->
|
60
|
+
count = 0
|
61
|
+
|
62
|
+
for goal_entity in goal_entities
|
63
|
+
count += 1 unless (entity for entity in entities when entity[0] == goal_entity[0]).length > 0
|
64
|
+
|
65
|
+
count
|
66
|
+
|
67
|
+
count_score: (entities, goal_entities) ->
|
68
|
+
sum = 0
|
69
|
+
|
70
|
+
for goal_entity in goal_entities
|
71
|
+
found_entity = (entity for entity in entities when entity[0] == goal_entity[0])[0]
|
72
|
+
|
73
|
+
if found_entity?
|
74
|
+
sum += Math.abs(found_entity.length - goal_entity.length)
|
75
|
+
|
76
|
+
sum
|
77
|
+
|
78
|
+
rank: (goal_pattern) ->
|
79
|
+
separated_goal_pattern = this.separate(goal_pattern)
|
80
|
+
result = {}
|
81
|
+
|
82
|
+
for separated_pattern in this.all_separated_patterns()
|
83
|
+
result[separated_pattern.join("")] = this.score(separated_pattern, separated_goal_pattern)
|
84
|
+
|
85
|
+
result
|
@@ -1,240 +1,262 @@
|
|
1
1
|
# Copyright 2012 Twitter, Inc
|
2
2
|
# http://www.apache.org/licenses/LICENSE-2.0
|
3
3
|
|
4
|
-
TwitterCldr.DateTimeFormatter
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
4
|
+
class TwitterCldr.DateTimeFormatter
|
5
|
+
constructor: ->
|
6
|
+
@tokens = `{{{tokens}}}`
|
7
|
+
@weekday_keys = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]
|
8
|
+
@methods = # ignoring u, l, g, j, A
|
9
|
+
'G': 'era'
|
10
|
+
'y': 'year'
|
11
|
+
'Y': 'year_of_week_of_year'
|
12
|
+
'Q': 'quarter'
|
13
|
+
'q': 'quarter_stand_alone'
|
14
|
+
'M': 'month'
|
15
|
+
'L': 'month_stand_alone'
|
16
|
+
'w': 'week_of_year'
|
17
|
+
'W': 'week_of_month'
|
18
|
+
'd': 'day'
|
19
|
+
'D': 'day_of_month'
|
20
|
+
'F': 'day_of_week_in_month'
|
21
|
+
'E': 'weekday'
|
22
|
+
'e': 'weekday_local'
|
23
|
+
'c': 'weekday_local_stand_alone'
|
24
|
+
'a': 'period'
|
25
|
+
'h': 'hour'
|
26
|
+
'H': 'hour'
|
27
|
+
'K': 'hour'
|
28
|
+
'k': 'hour'
|
29
|
+
'm': 'minute'
|
30
|
+
's': 'second'
|
31
|
+
'S': 'second_fraction'
|
32
|
+
'z': 'timezone'
|
33
|
+
'Z': 'timezone'
|
34
|
+
'v': 'timezone_generic_non_location'
|
35
|
+
'V': 'timezone_metazone'
|
36
|
+
|
37
|
+
format: (obj, options) ->
|
38
|
+
format_token = (token) =>
|
39
|
+
result = ""
|
40
|
+
|
41
|
+
switch token.type
|
42
|
+
when "pattern"
|
43
|
+
this.result_for_token(token, obj)
|
44
|
+
else
|
45
|
+
if token.value.length > 0 && token.value[0] == "'" && token.value[token.value.length - 1] == "'"
|
46
|
+
token.value.substring(1, token.value.length - 1)
|
47
|
+
else
|
48
|
+
token.value
|
49
|
+
|
50
|
+
tokens = this.get_tokens(obj, options)
|
51
|
+
(format_token(token) for token in tokens).join("")
|
52
|
+
|
53
|
+
get_tokens: (obj, options) ->
|
54
|
+
format = options.format || "date_time"
|
55
|
+
type = options.type || "default"
|
56
|
+
|
57
|
+
if format == "additional"
|
58
|
+
@tokens["date_time"][format][this.additional_format_selector().find_closest(options.type)]
|
59
|
+
else
|
60
|
+
@tokens[format][type]
|
61
|
+
|
62
|
+
result_for_token: (token, date) ->
|
63
|
+
this[@methods[token.value[0]]](date, token.value, token.value.length)
|
64
|
+
|
65
|
+
additional_format_selector: ->
|
66
|
+
new TwitterCldr.AdditionalDateFormatSelector(@tokens["date_time"]["additional"])
|
67
|
+
|
68
|
+
@additional_formats: ->
|
69
|
+
new TwitterCldr.DateTimeFormatter().additional_format_selector().patterns()
|
70
|
+
|
71
|
+
era: (date, pattern, length) ->
|
72
|
+
switch length
|
73
|
+
when 0
|
74
|
+
choices = ["", ""]
|
62
75
|
when 1, 2, 3
|
63
|
-
choices =
|
76
|
+
choices = TwitterCldr.Calendar.calendar["eras"]["abbr"]
|
64
77
|
else
|
65
|
-
choices =
|
78
|
+
choices = TwitterCldr.Calendar.calendar["eras"]["name"]
|
66
79
|
|
67
80
|
index = if (date.getFullYear() < 0) then 0 else 1
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
81
|
+
result = choices[index]
|
82
|
+
|
83
|
+
if result? then result else this.era(date, pattern[0..-2], length - 1)
|
84
|
+
|
85
|
+
year: (date, pattern, length) ->
|
86
|
+
year = date.getFullYear().toString()
|
87
|
+
|
88
|
+
if length == 2
|
89
|
+
if year.length != 1
|
90
|
+
year = year.slice(-2)
|
91
|
+
|
92
|
+
if length > 1
|
93
|
+
year = ("0000" + year).slice(-length)
|
94
|
+
|
95
|
+
year
|
96
|
+
|
97
|
+
year_of_week_of_year: (date, pattern, length) ->
|
98
|
+
throw 'not implemented'
|
99
|
+
|
100
|
+
day_of_week_in_month: (date, pattern, length) -> # e.g. 2nd Wed in July
|
101
|
+
throw 'not implemented'
|
102
|
+
|
103
|
+
quarter: (date, pattern, length) ->
|
104
|
+
# the bitwise OR is used here to truncate the decimal produced by the / 3
|
105
|
+
quarter = ((date.getMonth() / 3) | 0) + 1
|
106
|
+
|
107
|
+
switch length
|
108
|
+
when 1
|
109
|
+
quarter.toString()
|
110
|
+
when 2
|
111
|
+
("0000" + quarter.toString()).slice(-length)
|
112
|
+
when 3
|
113
|
+
TwitterCldr.Calendar.calendar.quarters.format.abbreviated[quarter]
|
114
|
+
when 4
|
115
|
+
TwitterCldr.Calendar.calendar.quarters.format.wide[quarter]
|
116
|
+
|
117
|
+
quarter_stand_alone: (date, pattern, length) ->
|
118
|
+
quarter = (date.getMonth() - 1) / 3 + 1
|
119
|
+
|
120
|
+
switch length
|
121
|
+
when 1
|
122
|
+
quarter.toString()
|
123
|
+
when 2
|
124
|
+
("0000" + quarter.toString()).slice(-length)
|
125
|
+
when 3
|
126
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
|
127
|
+
when 4
|
128
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
|
129
|
+
when 5
|
130
|
+
TwitterCldr.Calendar.calendar.quarters['stand-alone'].narrow[quarter]
|
131
|
+
|
132
|
+
month: (date, pattern, length) ->
|
133
|
+
month_str = (date.getMonth() + 1).toString()
|
134
|
+
|
135
|
+
switch length
|
136
|
+
when 1
|
137
|
+
month_str
|
138
|
+
when 2
|
139
|
+
("0000" + month_str).slice(-length)
|
140
|
+
when 3
|
141
|
+
TwitterCldr.Calendar.calendar.months.format.abbreviated[month_str]
|
142
|
+
when 4
|
143
|
+
TwitterCldr.Calendar.calendar.months.format.wide[month_str]
|
144
|
+
when 5
|
145
|
+
throw 'not yet implemented (requires cldr\'s "multiple inheritance")'
|
146
|
+
else
|
147
|
+
throw "Unknown date format"
|
148
|
+
|
149
|
+
month_stand_alone: (date, pattern, length) ->
|
150
|
+
month_str = (date.getMonth() + 1).toString()
|
151
|
+
|
152
|
+
switch length
|
153
|
+
when 1
|
154
|
+
month_str
|
155
|
+
when 2
|
156
|
+
("0000" + month_str).slice(-length)
|
157
|
+
when 3
|
158
|
+
TwitterCldr.Calendar.calendar.months['stand-alone'].abbreviated[month_str]
|
159
|
+
when 4
|
160
|
+
TwitterCldr.Calendar.calendar.months['stand-alone'].wide[month_str]
|
161
|
+
when 5
|
162
|
+
TwitterCldr.Calendar.calendar.months['stand-alone'].narrow[month_str]
|
163
|
+
else
|
164
|
+
throw "Unknown date format"
|
165
|
+
|
166
|
+
day: (date, pattern, length) ->
|
167
|
+
switch length
|
168
|
+
when 1
|
169
|
+
date.getDate().toString()
|
170
|
+
when 2
|
171
|
+
("0000" + date.getDate().toString()).slice(-length)
|
172
|
+
|
173
|
+
weekday: (date, pattern, length) ->
|
174
|
+
key = @weekday_keys[date.getDay()]
|
175
|
+
|
176
|
+
switch length
|
177
|
+
when 1, 2, 3
|
178
|
+
TwitterCldr.Calendar.calendar.days.format.abbreviated[key]
|
179
|
+
when 4
|
180
|
+
TwitterCldr.Calendar.calendar.days.format.wide[key]
|
181
|
+
when 5
|
182
|
+
TwitterCldr.Calendar.calendar.days['stand-alone'].narrow[key]
|
183
|
+
|
184
|
+
weekday_local: (date, pattern, length) ->
|
185
|
+
# "Like E except adds a numeric value depending on the local starting day of the week"
|
169
186
|
# CLDR does not contain data as to which day is the first day of the week, so we will assume Monday (Ruby default)
|
170
|
-
|
187
|
+
switch length
|
171
188
|
when 1, 2
|
172
189
|
day = date.getDay()
|
173
|
-
|
190
|
+
if day == 0 then "7" else day.toString()
|
174
191
|
else
|
175
|
-
|
192
|
+
this.weekday(date, pattern, length)
|
176
193
|
|
177
|
-
|
178
|
-
|
194
|
+
weekday_local_stand_alone: (date, pattern, length) ->
|
195
|
+
switch length
|
179
196
|
when 1
|
180
|
-
|
197
|
+
this.weekday_local(date, pattern, length)
|
181
198
|
else
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
199
|
+
this.weekday(date, pattern, length)
|
200
|
+
|
201
|
+
period: (time, pattern, length) ->
|
202
|
+
if time.getHours() > 11
|
203
|
+
TwitterCldr.Calendar.calendar.periods.format.wide["pm"]
|
204
|
+
else
|
205
|
+
TwitterCldr.Calendar.calendar.periods.format.wide["am"]
|
206
|
+
|
207
|
+
hour: (time, pattern, length) ->
|
208
|
+
hour = time.getHours()
|
209
|
+
|
210
|
+
switch pattern[0]
|
211
|
+
when 'h'
|
212
|
+
if hour > 12
|
213
|
+
hour = hour - 12
|
214
|
+
else if hour == 0
|
215
|
+
hour = 12
|
216
|
+
when 'K'
|
217
|
+
if hour > 11
|
218
|
+
hour = hour - 12
|
219
|
+
when 'k'
|
220
|
+
if hour == 0
|
221
|
+
hour = 24
|
222
|
+
|
223
|
+
if length == 1
|
224
|
+
hour.toString()
|
225
|
+
else
|
226
|
+
("000000" + hour.toString()).slice(-length)
|
227
|
+
|
228
|
+
minute: (time, pattern, length) ->
|
229
|
+
if length == 1
|
230
|
+
time.getMinutes().toString()
|
231
|
+
else
|
232
|
+
("000000" + time.getMinutes().toString()).slice(-length)
|
233
|
+
|
234
|
+
second: (time, pattern, length) ->
|
235
|
+
if length == 1
|
236
|
+
time.getSeconds().toString()
|
237
|
+
else
|
238
|
+
("000000" + time.getSeconds().toString()).slice(-length)
|
239
|
+
|
240
|
+
second_fraction: (time, pattern, length) ->
|
241
|
+
if length > 6
|
242
|
+
throw 'can not use the S format with more than 6 digits'
|
243
|
+
|
244
|
+
("000000" + Math.round(Math.pow(time.getMilliseconds() * 100.0, 6 - length)).toString()).slice(-length)
|
245
|
+
|
246
|
+
timezone: (time, pattern, length) ->
|
247
|
+
offset = time.getTimezoneOffset()
|
248
|
+
|
249
|
+
hours = ("00" + (Math.abs(offset) / 60).toString()).slice(-2)
|
250
|
+
minutes = ("00" + (Math.abs(offset) % 60).toString()).slice(-2)
|
251
|
+
sign = if offset > 0 then "-" else "+" # timezone sign is opposite to offset sign
|
252
|
+
|
253
|
+
offsetString = sign + hours + ":" + minutes
|
254
|
+
|
255
|
+
switch length
|
256
|
+
when 1, 2, 3
|
257
|
+
offsetString
|
258
|
+
else
|
259
|
+
"UTC" + offsetString
|
260
|
+
|
261
|
+
timezone_generic_non_location: (time, pattern, length) ->
|
262
|
+
throw 'not yet implemented (requires timezone translation data")'
|