Debian Codegraph @

closure-library/closure/goog/date/relativewithplurals_test.js

raw
1 // Copyright 2009 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.date.relativeWithPluralsTest');
16 goog.setTestOnly('goog.date.relativeWithPluralsTest');
17
18 goog.require('goog.date.relative');
19 /** @suppress {extraRequire} Include shared tests. */
20 goog.require('goog.date.relativeCommonTests');
21 /** @suppress {extraRequire} Included for side effects. */
22 goog.require('goog.date.relativeWithPlurals');
23 goog.require('goog.i18n.DateTimeFormat');
24 goog.require('goog.i18n.DateTimeSymbols');
25 goog.require('goog.i18n.DateTimeSymbols_bn'); // Bengali
26 goog.require('goog.i18n.DateTimeSymbols_en');
27 goog.require('goog.i18n.DateTimeSymbols_fa'); // Persian
28 goog.require('goog.i18n.NumberFormatSymbols');
29 goog.require('goog.i18n.NumberFormatSymbols_bn'); // Bengali
30 goog.require('goog.i18n.NumberFormatSymbols_en');
31 goog.require('goog.i18n.NumberFormatSymbols_fa'); // Persian
32
33
34 function tearDown() {
35 goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_en;
36 goog.i18n.NumberFormatSymbols = goog.i18n.NumberFormatSymbols_en;
37 }
38
39 function testFormatRelativeForPastDatesPersianDigits() {
40 goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_fa;
41 goog.i18n.NumberFormatSymbols = goog.i18n.NumberFormatSymbols_fa;
42 var fn = goog.date.relative.format;
43
44 // The text here is English, as it comes from localized resources, not
45 // from CLDR. It works properly in production, but it's not loaded here.
46 // Will need to wait for CLDR 24, when the data we need will be available,
47 // so that we can add it to DateTimeSymbols and out of localization.
48
49 // For Persian \u06F0 is the base, so \u6F0 = digit 0, \u6F5 = digit 5 ...
50 // "Western" digits in square brackets for convenience
51 assertEquals(
52 'Should round seconds to the minute below',
53 localizeNumber(0) + ' minutes ago', // ۰ minutes ago
54 fn(timestamp('23 March 2009 14:30:10')));
55
56 assertEquals(
57 'Should round seconds to the minute below',
58 localizeNumber(1) + ' minute ago', // ۱ minute ago
59 fn(timestamp('23 March 2009 14:29:56')));
60
61 assertEquals(
62 'Should round seconds to the minute below',
63 localizeNumber(2) + ' minutes ago', // ۲ minutes ago
64 fn(timestamp('23 March 2009 14:29:00')));
65
66 assertEquals(
67 localizeNumber(10) + ' minutes ago', // ۱۰ minutes ago
68 fn(timestamp('23 March 2009 14:20:10')));
69 assertEquals(
70 localizeNumber(59) + ' minutes ago', // ۵۹ minutes ago
71 fn(timestamp('23 March 2009 13:31:42')));
72 assertEquals(
73 localizeNumber(2) + ' hours ago', // ۲ hours ago
74 fn(timestamp('23 March 2009 12:20:56')));
75 assertEquals(
76 localizeNumber(23) + ' hours ago', // ۲۳ hours ago
77 fn(timestamp('22 March 2009 15:30:56')));
78 assertEquals(
79 localizeNumber(1) + ' day ago', // ۱ day ago
80 fn(timestamp('22 March 2009 12:11:04')));
81 assertEquals(
82 localizeNumber(1) + ' day ago', // ۱ day ago
83 fn(timestamp('22 March 2009 00:00:00')));
84 assertEquals(
85 localizeNumber(2) + ' days ago', // ۲ days ago
86 fn(timestamp('21 March 2009 23:59:59')));
87 assertEquals(
88 localizeNumber(2) + ' days ago', // ۲ days ago
89 fn(timestamp('21 March 2009 10:30:56')));
90 assertEquals(
91 localizeNumber(2) + ' days ago', // ۲ days ago
92 fn(timestamp('21 March 2009 00:00:00')));
93 assertEquals(
94 localizeNumber(3) + ' days ago', // ۳ days ago
95 fn(timestamp('20 March 2009 23:59:59')));
96 }
97
98 function testFormatRelativeForFutureDatesBengaliDigits() {
99 var fn = goog.date.relative.format;
100 goog.i18n.DateTimeSymbols = goog.i18n.DateTimeSymbols_bn;
101 goog.i18n.NumberFormatSymbols = goog.i18n.NumberFormatSymbols_bn;
102
103 // For Bengali \u09E6 is the base, so \u09E6 = digit 0, \u09EB = digit 5
104 // "Western" digits in square brackets for convenience
105 assertEquals(
106 'Should round seconds to the minute below',
107 'in ' + localizeNumber(1) + ' minute', // in ১ minute
108 fn(timestamp('23 March 2009 14:32:05')));
109
110 assertEquals(
111 'Should round seconds to the minute below',
112 'in ' + localizeNumber(2) + ' minutes', // in ২ minutes
113 fn(timestamp('23 March 2009 14:33:00')));
114
115 assertEquals(
116 'in ' + localizeNumber(10) + ' minutes', // in ১০ minutes
117 fn(timestamp('23 March 2009 14:40:10')));
118 assertEquals(
119 'in ' + localizeNumber(59) + ' minutes', // in ৫৯ minutes
120 fn(timestamp('23 March 2009 15:29:15')));
121 assertEquals(
122 'in ' + localizeNumber(2) + ' hours', // in ২ hours
123 fn(timestamp('23 March 2009 17:20:56')));
124 assertEquals(
125 'in ' + localizeNumber(23) + ' hours', // in ২৩ hours
126 fn(timestamp('24 March 2009 13:30:56')));
127 assertEquals(
128 'in ' + localizeNumber(1) + ' day', // in ১ day
129 fn(timestamp('24 March 2009 14:31:07')));
130 assertEquals(
131 'in ' + localizeNumber(1) + ' day', // in ১ day
132 fn(timestamp('24 March 2009 16:11:04')));
133 assertEquals(
134 'in ' + localizeNumber(1) + ' day', // in ১ day
135 fn(timestamp('24 March 2009 23:59:59')));
136 assertEquals(
137 'in ' + localizeNumber(2) + ' days', // in ২ days
138 fn(timestamp('25 March 2009 00:00:00')));
139 assertEquals(
140 'in ' + localizeNumber(2) + ' days', // in ২ days
141 fn(timestamp('25 March 2009 10:30:56')));
142 assertEquals(
143 'in ' + localizeNumber(2) + ' days', // in ২ days
144 fn(timestamp('25 March 2009 23:59:59')));
145 assertEquals(
146 'in ' + localizeNumber(3) + ' days', // in ৩ days
147 fn(timestamp('26 March 2009 00:00:00')));
148 }
149
150 function localizeNumber(value) {
151 // Quick conversion to national digits, to increase readability of the
152 // tests above.
153 return goog.i18n.DateTimeFormat.localizeNumbers(value);
154 }