format-en.js 24.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The following test are not part of the comformance. Just some output in
// English to verify the format does return something reasonable for English.
// It may be changed when we update the CLDR data.
// NOTE: These are UNSPECIFIED behavior in
// http://tc39.github.io/proposal-intl-relative-time/

let longAuto = new Intl.RelativeTimeFormat(
    "en", {style: "long", localeMatcher: 'lookup', numeric: 'auto'});

14 15 16
assertEquals('3 seconds ago', longAuto.format(-3, 'second'));
assertEquals('2 seconds ago', longAuto.format(-2, 'second'));
assertEquals('1 second ago', longAuto.format(-1, 'second'));
17 18
assertEquals('now', longAuto.format(0, 'second'));
assertEquals('now', longAuto.format(-0, 'second'));
19 20
assertEquals('in 1 second', longAuto.format(1, 'second'));
assertEquals('in 2 seconds', longAuto.format(2, 'second'));
21 22
assertEquals('in 345 seconds', longAuto.format(345, 'second'));

23 24 25
assertEquals('3 minutes ago', longAuto.format(-3, 'minute'));
assertEquals('2 minutes ago', longAuto.format(-2, 'minute'));
assertEquals('1 minute ago', longAuto.format(-1, 'minute'));
Frank Tang's avatar
Frank Tang committed
26 27
assertEquals('this minute', longAuto.format(0, 'minute'));
assertEquals('this minute', longAuto.format(-0, 'minute'));
28 29
assertEquals('in 1 minute', longAuto.format(1, 'minute'));
assertEquals('in 2 minutes', longAuto.format(2, 'minute'));
30 31
assertEquals('in 345 minutes', longAuto.format(345, 'minute'));

32 33 34
assertEquals('3 hours ago', longAuto.format(-3, 'hour'));
assertEquals('2 hours ago', longAuto.format(-2, 'hour'));
assertEquals('1 hour ago', longAuto.format(-1, 'hour'));
Frank Tang's avatar
Frank Tang committed
35 36
assertEquals('this hour', longAuto.format(0, 'hour'));
assertEquals('this hour', longAuto.format(-0, 'hour'));
37 38
assertEquals('in 1 hour', longAuto.format(1, 'hour'));
assertEquals('in 2 hours', longAuto.format(2, 'hour'));
39 40
assertEquals('in 345 hours', longAuto.format(345, 'hour'));

41 42
assertEquals('3 days ago', longAuto.format(-3, 'day'));
assertEquals('2 days ago', longAuto.format(-2, 'day'));
43 44 45 46
assertEquals('yesterday', longAuto.format(-1, 'day'));
assertEquals('today', longAuto.format(0, 'day'));
assertEquals('today', longAuto.format(-0, 'day'));
assertEquals('tomorrow', longAuto.format(1, 'day'));
47
assertEquals('in 2 days', longAuto.format(2, 'day'));
48 49
assertEquals('in 345 days', longAuto.format(345, 'day'));

50 51
assertEquals('3 weeks ago', longAuto.format(-3, 'week'));
assertEquals('2 weeks ago', longAuto.format(-2, 'week'));
52 53 54 55
assertEquals('last week', longAuto.format(-1, 'week'));
assertEquals('this week', longAuto.format(0, 'week'));
assertEquals('this week', longAuto.format(-0, 'week'));
assertEquals('next week', longAuto.format(1, 'week'));
56
assertEquals('in 2 weeks', longAuto.format(2, 'week'));
57 58
assertEquals('in 345 weeks', longAuto.format(345, 'week'));

59 60
assertEquals('3 months ago', longAuto.format(-3, 'month'));
assertEquals('2 months ago', longAuto.format(-2, 'month'));
61 62 63 64
assertEquals('last month', longAuto.format(-1, 'month'));
assertEquals('this month', longAuto.format(0, 'month'));
assertEquals('this month', longAuto.format(-0, 'month'));
assertEquals('next month', longAuto.format(1, 'month'));
65
assertEquals('in 2 months', longAuto.format(2, 'month'));
66 67
assertEquals('in 345 months', longAuto.format(345, 'month'));

68 69
assertEquals('3 quarters ago', longAuto.format(-3, 'quarter'));
assertEquals('2 quarters ago', longAuto.format(-2, 'quarter'));
70 71 72 73
assertEquals('last quarter', longAuto.format(-1, 'quarter'));
assertEquals('this quarter', longAuto.format(0, 'quarter'));
assertEquals('this quarter', longAuto.format(-0, 'quarter'));
assertEquals('next quarter', longAuto.format(1, 'quarter'));
74
assertEquals('in 2 quarters', longAuto.format(2, 'quarter'));
75 76
assertEquals('in 345 quarters', longAuto.format(345, 'quarter'));

77 78
assertEquals('3 years ago', longAuto.format(-3, 'year'));
assertEquals('2 years ago', longAuto.format(-2, 'year'));
79 80 81 82
assertEquals('last year', longAuto.format(-1, 'year'));
assertEquals('this year', longAuto.format(0, 'year'));
assertEquals('this year', longAuto.format(-0, 'year'));
assertEquals('next year', longAuto.format(1, 'year'));
83
assertEquals('in 2 years', longAuto.format(2, 'year'));
84 85 86 87 88
assertEquals('in 345 years', longAuto.format(345, 'year'));

let shortAuto = new Intl.RelativeTimeFormat(
    "en", {style: "short", localeMatcher: 'lookup', numeric: 'auto'});

89 90 91
assertEquals('3 sec. ago', shortAuto.format(-3, 'second'));
assertEquals('2 sec. ago', shortAuto.format(-2, 'second'));
assertEquals('1 sec. ago', shortAuto.format(-1, 'second'));
92 93
assertEquals('now', shortAuto.format(0, 'second'));
assertEquals('now', shortAuto.format(-0, 'second'));
94 95
assertEquals('in 1 sec.', shortAuto.format(1, 'second'));
assertEquals('in 2 sec.', shortAuto.format(2, 'second'));
96 97
assertEquals('in 345 sec.', shortAuto.format(345, 'second'));

98 99 100
assertEquals('3 min. ago', shortAuto.format(-3, 'minute'));
assertEquals('2 min. ago', shortAuto.format(-2, 'minute'));
assertEquals('1 min. ago', shortAuto.format(-1, 'minute'));
Frank Tang's avatar
Frank Tang committed
101 102
assertEquals('this minute', shortAuto.format(0, 'minute'));
assertEquals('this minute', shortAuto.format(-0, 'minute'));
103 104
assertEquals('in 1 min.', shortAuto.format(1, 'minute'));
assertEquals('in 2 min.', shortAuto.format(2, 'minute'));
105 106
assertEquals('in 345 min.', shortAuto.format(345, 'minute'));

107 108 109
assertEquals('3 hr. ago', shortAuto.format(-3, 'hour'));
assertEquals('2 hr. ago', shortAuto.format(-2, 'hour'));
assertEquals('1 hr. ago', shortAuto.format(-1, 'hour'));
Frank Tang's avatar
Frank Tang committed
110 111
assertEquals('this hour', shortAuto.format(0, 'hour'));
assertEquals('this hour', shortAuto.format(-0, 'hour'));
112 113
assertEquals('in 1 hr.', shortAuto.format(1, 'hour'));
assertEquals('in 2 hr.', shortAuto.format(2, 'hour'));
114 115
assertEquals('in 345 hr.', shortAuto.format(345, 'hour'));

116 117
assertEquals('3 days ago', shortAuto.format(-3, 'day'));
assertEquals('2 days ago', shortAuto.format(-2, 'day'));
118 119 120 121
assertEquals('yesterday', shortAuto.format(-1, 'day'));
assertEquals('today', shortAuto.format(0, 'day'));
assertEquals('today', shortAuto.format(-0, 'day'));
assertEquals('tomorrow', shortAuto.format(1, 'day'));
122
assertEquals('in 2 days', shortAuto.format(2, 'day'));
123 124
assertEquals('in 345 days', shortAuto.format(345, 'day'));

125 126
assertEquals('3 wk. ago', shortAuto.format(-3, 'week'));
assertEquals('2 wk. ago', shortAuto.format(-2, 'week'));
127 128 129 130
assertEquals('last wk.', shortAuto.format(-1, 'week'));
assertEquals('this wk.', shortAuto.format(0, 'week'));
assertEquals('this wk.', shortAuto.format(-0, 'week'));
assertEquals('next wk.', shortAuto.format(1, 'week'));
131
assertEquals('in 2 wk.', shortAuto.format(2, 'week'));
132 133
assertEquals('in 345 wk.', shortAuto.format(345, 'week'));

134 135
assertEquals('3 mo. ago', shortAuto.format(-3, 'month'));
assertEquals('2 mo. ago', shortAuto.format(-2, 'month'));
136 137 138 139
assertEquals('last mo.', shortAuto.format(-1, 'month'));
assertEquals('this mo.', shortAuto.format(0, 'month'));
assertEquals('this mo.', shortAuto.format(-0, 'month'));
assertEquals('next mo.', shortAuto.format(1, 'month'));
140
assertEquals('in 2 mo.', shortAuto.format(2, 'month'));
141 142
assertEquals('in 345 mo.', shortAuto.format(345, 'month'));

143 144
assertEquals('3 qtrs. ago', shortAuto.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', shortAuto.format(-2, 'quarter'));
145 146 147 148
assertEquals('last qtr.', shortAuto.format(-1, 'quarter'));
assertEquals('this qtr.', shortAuto.format(0, 'quarter'));
assertEquals('this qtr.', shortAuto.format(-0, 'quarter'));
assertEquals('next qtr.', shortAuto.format(1, 'quarter'));
149
assertEquals('in 2 qtrs.', shortAuto.format(2, 'quarter'));
150 151
assertEquals('in 345 qtrs.', shortAuto.format(345, 'quarter'));

152 153
assertEquals('3 yr. ago', shortAuto.format(-3, 'year'));
assertEquals('2 yr. ago', shortAuto.format(-2, 'year'));
154 155 156 157
assertEquals('last yr.', shortAuto.format(-1, 'year'));
assertEquals('this yr.', shortAuto.format(0, 'year'));
assertEquals('this yr.', shortAuto.format(-0, 'year'));
assertEquals('next yr.', shortAuto.format(1, 'year'));
158
assertEquals('in 2 yr.', shortAuto.format(2, 'year'));
159 160 161 162 163 164
assertEquals('in 345 yr.', shortAuto.format(345, 'year'));

// Somehow in the 'en' locale, there are no valeu for -narrow
let narrowAuto = new Intl.RelativeTimeFormat(
    "en", {style: "narrow", localeMatcher: 'lookup', numeric: 'auto'});

165 166 167
assertEquals('3 sec. ago', narrowAuto.format(-3, 'second'));
assertEquals('2 sec. ago', narrowAuto.format(-2, 'second'));
assertEquals('1 sec. ago', narrowAuto.format(-1, 'second'));
168 169
assertEquals('now', narrowAuto.format(0, 'second'));
assertEquals('now', narrowAuto.format(-0, 'second'));
170 171
assertEquals('in 1 sec.', narrowAuto.format(1, 'second'));
assertEquals('in 2 sec.', narrowAuto.format(2, 'second'));
172 173
assertEquals('in 345 sec.', narrowAuto.format(345, 'second'));

174 175 176
assertEquals('3 min. ago', narrowAuto.format(-3, 'minute'));
assertEquals('2 min. ago', narrowAuto.format(-2, 'minute'));
assertEquals('1 min. ago', narrowAuto.format(-1, 'minute'));
Frank Tang's avatar
Frank Tang committed
177 178
assertEquals('this minute', narrowAuto.format(0, 'minute'));
assertEquals('this minute', narrowAuto.format(-0, 'minute'));
179 180
assertEquals('in 1 min.', narrowAuto.format(1, 'minute'));
assertEquals('in 2 min.', narrowAuto.format(2, 'minute'));
181 182
assertEquals('in 345 min.', narrowAuto.format(345, 'minute'));

183 184 185
assertEquals('3 hr. ago', narrowAuto.format(-3, 'hour'));
assertEquals('2 hr. ago', narrowAuto.format(-2, 'hour'));
assertEquals('1 hr. ago', narrowAuto.format(-1, 'hour'));
Frank Tang's avatar
Frank Tang committed
186 187
assertEquals('this hour', narrowAuto.format(0, 'hour'));
assertEquals('this hour', narrowAuto.format(-0, 'hour'));
188 189
assertEquals('in 1 hr.', narrowAuto.format(1, 'hour'));
assertEquals('in 2 hr.', narrowAuto.format(2, 'hour'));
190 191
assertEquals('in 345 hr.', narrowAuto.format(345, 'hour'));

192 193
assertEquals('3 days ago', narrowAuto.format(-3, 'day'));
assertEquals('2 days ago', narrowAuto.format(-2, 'day'));
194 195 196 197
assertEquals('yesterday', narrowAuto.format(-1, 'day'));
assertEquals('today', narrowAuto.format(0, 'day'));
assertEquals('today', narrowAuto.format(-0, 'day'));
assertEquals('tomorrow', narrowAuto.format(1, 'day'));
198
assertEquals('in 2 days', narrowAuto.format(2, 'day'));
199 200
assertEquals('in 345 days', narrowAuto.format(345, 'day'));

201 202
assertEquals('3 wk. ago', narrowAuto.format(-3, 'week'));
assertEquals('2 wk. ago', narrowAuto.format(-2, 'week'));
203 204 205 206
assertEquals('last wk.', narrowAuto.format(-1, 'week'));
assertEquals('this wk.', narrowAuto.format(0, 'week'));
assertEquals('this wk.', narrowAuto.format(-0, 'week'));
assertEquals('next wk.', narrowAuto.format(1, 'week'));
207
assertEquals('in 2 wk.', narrowAuto.format(2, 'week'));
208 209
assertEquals('in 345 wk.', narrowAuto.format(345, 'week'));

210 211
assertEquals('3 mo. ago', narrowAuto.format(-3, 'month'));
assertEquals('2 mo. ago', narrowAuto.format(-2, 'month'));
212 213 214 215
assertEquals('last mo.', narrowAuto.format(-1, 'month'));
assertEquals('this mo.', narrowAuto.format(0, 'month'));
assertEquals('this mo.', narrowAuto.format(-0, 'month'));
assertEquals('next mo.', narrowAuto.format(1, 'month'));
216
assertEquals('in 2 mo.', narrowAuto.format(2, 'month'));
217 218
assertEquals('in 345 mo.', narrowAuto.format(345, 'month'));

219 220
assertEquals('3 qtrs. ago', narrowAuto.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', narrowAuto.format(-2, 'quarter'));
221 222 223 224
assertEquals('last qtr.', narrowAuto.format(-1, 'quarter'));
assertEquals('this qtr.', narrowAuto.format(0, 'quarter'));
assertEquals('this qtr.', narrowAuto.format(-0, 'quarter'));
assertEquals('next qtr.', narrowAuto.format(1, 'quarter'));
225
assertEquals('in 2 qtrs.', narrowAuto.format(2, 'quarter'));
226 227
assertEquals('in 345 qtrs.', narrowAuto.format(345, 'quarter'));

228 229
assertEquals('3 yr. ago', narrowAuto.format(-3, 'year'));
assertEquals('2 yr. ago', narrowAuto.format(-2, 'year'));
230 231 232 233
assertEquals('last yr.', narrowAuto.format(-1, 'year'));
assertEquals('this yr.', narrowAuto.format(0, 'year'));
assertEquals('this yr.', narrowAuto.format(-0, 'year'));
assertEquals('next yr.', narrowAuto.format(1, 'year'));
234
assertEquals('in 2 yr.', narrowAuto.format(2, 'year'));
235 236 237 238 239
assertEquals('in 345 yr.', narrowAuto.format(345, 'year'));

let longAlways = new Intl.RelativeTimeFormat(
    "en", {style: "long", localeMatcher: 'lookup', numeric: 'always'});

240 241 242 243 244 245 246
assertEquals('3 seconds ago', longAlways.format(-3, 'second'));
assertEquals('2 seconds ago', longAlways.format(-2, 'second'));
assertEquals('1 second ago', longAlways.format(-1, 'second'));
assertEquals('in 0 seconds', longAlways.format(0, 'second'));
assertEquals('0 seconds ago', longAlways.format(-0, 'second'));
assertEquals('in 1 second', longAlways.format(1, 'second'));
assertEquals('in 2 seconds', longAlways.format(2, 'second'));
247 248
assertEquals('in 345 seconds', longAlways.format(345, 'second'));

249 250 251 252 253 254 255
assertEquals('3 minutes ago', longAlways.format(-3, 'minute'));
assertEquals('2 minutes ago', longAlways.format(-2, 'minute'));
assertEquals('1 minute ago', longAlways.format(-1, 'minute'));
assertEquals('in 0 minutes', longAlways.format(0, 'minute'));
assertEquals('0 minutes ago', longAlways.format(-0, 'minute'));
assertEquals('in 1 minute', longAlways.format(1, 'minute'));
assertEquals('in 2 minutes', longAlways.format(2, 'minute'));
256 257
assertEquals('in 345 minutes', longAlways.format(345, 'minute'));

258 259 260 261 262 263 264
assertEquals('3 hours ago', longAlways.format(-3, 'hour'));
assertEquals('2 hours ago', longAlways.format(-2, 'hour'));
assertEquals('1 hour ago', longAlways.format(-1, 'hour'));
assertEquals('in 0 hours', longAlways.format(0, 'hour'));
assertEquals('0 hours ago', longAlways.format(-0, 'hour'));
assertEquals('in 1 hour', longAlways.format(1, 'hour'));
assertEquals('in 2 hours', longAlways.format(2, 'hour'));
265 266
assertEquals('in 345 hours', longAlways.format(345, 'hour'));

267 268 269 270 271 272 273
assertEquals('3 days ago', longAlways.format(-3, 'day'));
assertEquals('2 days ago', longAlways.format(-2, 'day'));
assertEquals('1 day ago', longAlways.format(-1, 'day'));
assertEquals('in 0 days', longAlways.format(0, 'day'));
assertEquals('0 days ago', longAlways.format(-0, 'day'));
assertEquals('in 1 day', longAlways.format(1, 'day'));
assertEquals('in 2 days', longAlways.format(2, 'day'));
274 275
assertEquals('in 345 days', longAlways.format(345, 'day'));

276 277 278 279 280 281 282
assertEquals('3 weeks ago', longAlways.format(-3, 'week'));
assertEquals('2 weeks ago', longAlways.format(-2, 'week'));
assertEquals('1 week ago', longAlways.format(-1, 'week'));
assertEquals('in 0 weeks', longAlways.format(0, 'week'));
assertEquals('0 weeks ago', longAlways.format(-0, 'week'));
assertEquals('in 1 week', longAlways.format(1, 'week'));
assertEquals('in 2 weeks', longAlways.format(2, 'week'));
283 284
assertEquals('in 345 weeks', longAlways.format(345, 'week'));

285 286 287 288 289 290 291
assertEquals('3 months ago', longAlways.format(-3, 'month'));
assertEquals('2 months ago', longAlways.format(-2, 'month'));
assertEquals('1 month ago', longAlways.format(-1, 'month'));
assertEquals('in 0 months', longAlways.format(0, 'month'));
assertEquals('0 months ago', longAlways.format(-0, 'month'));
assertEquals('in 1 month', longAlways.format(1, 'month'));
assertEquals('in 2 months', longAlways.format(2, 'month'));
292 293
assertEquals('in 345 months', longAlways.format(345, 'month'));

294 295 296 297 298 299 300
assertEquals('3 quarters ago', longAlways.format(-3, 'quarter'));
assertEquals('2 quarters ago', longAlways.format(-2, 'quarter'));
assertEquals('1 quarter ago', longAlways.format(-1, 'quarter'));
assertEquals('in 0 quarters', longAlways.format(0, 'quarter'));
assertEquals('0 quarters ago', longAlways.format(-0, 'quarter'));
assertEquals('in 1 quarter', longAlways.format(1, 'quarter'));
assertEquals('in 2 quarters', longAlways.format(2, 'quarter'));
301 302
assertEquals('in 345 quarters', longAlways.format(345, 'quarter'));

303 304 305 306 307 308 309
assertEquals('3 years ago', longAlways.format(-3, 'year'));
assertEquals('2 years ago', longAlways.format(-2, 'year'));
assertEquals('1 year ago', longAlways.format(-1, 'year'));
assertEquals('in 0 years', longAlways.format(0, 'year'));
assertEquals('0 years ago', longAlways.format(-0, 'year'));
assertEquals('in 1 year', longAlways.format(1, 'year'));
assertEquals('in 2 years', longAlways.format(2, 'year'));
310 311 312 313 314
assertEquals('in 345 years', longAlways.format(345, 'year'));

let shortAlways = new Intl.RelativeTimeFormat(
    "en", {style: "short", localeMatcher: 'lookup', numeric: 'always'});

315 316 317 318 319 320 321
assertEquals('3 sec. ago', shortAlways.format(-3, 'second'));
assertEquals('2 sec. ago', shortAlways.format(-2, 'second'));
assertEquals('1 sec. ago', shortAlways.format(-1, 'second'));
assertEquals('in 0 sec.', shortAlways.format(0, 'second'));
assertEquals('0 sec. ago', shortAlways.format(-0, 'second'));
assertEquals('in 1 sec.', shortAlways.format(1, 'second'));
assertEquals('in 2 sec.', shortAlways.format(2, 'second'));
322 323
assertEquals('in 345 sec.', shortAlways.format(345, 'second'));

324 325 326 327 328 329 330
assertEquals('3 min. ago', shortAlways.format(-3, 'minute'));
assertEquals('2 min. ago', shortAlways.format(-2, 'minute'));
assertEquals('1 min. ago', shortAlways.format(-1, 'minute'));
assertEquals('in 0 min.', shortAlways.format(0, 'minute'));
assertEquals('0 min. ago', shortAlways.format(-0, 'minute'));
assertEquals('in 1 min.', shortAlways.format(1, 'minute'));
assertEquals('in 2 min.', shortAlways.format(2, 'minute'));
331 332
assertEquals('in 345 min.', shortAlways.format(345, 'minute'));

333 334 335 336 337 338 339
assertEquals('3 hr. ago', shortAlways.format(-3, 'hour'));
assertEquals('2 hr. ago', shortAlways.format(-2, 'hour'));
assertEquals('1 hr. ago', shortAlways.format(-1, 'hour'));
assertEquals('in 0 hr.', shortAlways.format(0, 'hour'));
assertEquals('0 hr. ago', shortAlways.format(-0, 'hour'));
assertEquals('in 1 hr.', shortAlways.format(1, 'hour'));
assertEquals('in 2 hr.', shortAlways.format(2, 'hour'));
340 341
assertEquals('in 345 hr.', shortAlways.format(345, 'hour'));

342 343 344 345 346 347 348
assertEquals('3 days ago', shortAlways.format(-3, 'day'));
assertEquals('2 days ago', shortAlways.format(-2, 'day'));
assertEquals('1 day ago', shortAlways.format(-1, 'day'));
assertEquals('in 0 days', shortAlways.format(0, 'day'));
assertEquals('0 days ago', shortAlways.format(-0, 'day'));
assertEquals('in 1 day', shortAlways.format(1, 'day'));
assertEquals('in 2 days', shortAlways.format(2, 'day'));
349 350
assertEquals('in 345 days', shortAlways.format(345, 'day'));

351 352 353 354 355 356 357
assertEquals('3 wk. ago', shortAlways.format(-3, 'week'));
assertEquals('2 wk. ago', shortAlways.format(-2, 'week'));
assertEquals('1 wk. ago', shortAlways.format(-1, 'week'));
assertEquals('in 0 wk.', shortAlways.format(0, 'week'));
assertEquals('0 wk. ago', shortAlways.format(-0, 'week'));
assertEquals('in 1 wk.', shortAlways.format(1, 'week'));
assertEquals('in 2 wk.', shortAlways.format(2, 'week'));
358 359
assertEquals('in 345 wk.', shortAlways.format(345, 'week'));

360 361 362 363 364 365 366
assertEquals('3 mo. ago', shortAlways.format(-3, 'month'));
assertEquals('2 mo. ago', shortAlways.format(-2, 'month'));
assertEquals('1 mo. ago', shortAlways.format(-1, 'month'));
assertEquals('in 0 mo.', shortAlways.format(0, 'month'));
assertEquals('0 mo. ago', shortAlways.format(-0, 'month'));
assertEquals('in 1 mo.', shortAlways.format(1, 'month'));
assertEquals('in 2 mo.', shortAlways.format(2, 'month'));
367 368
assertEquals('in 345 mo.', shortAlways.format(345, 'month'));

369 370 371 372
assertEquals('3 qtrs. ago', shortAlways.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', shortAlways.format(-2, 'quarter'));
assertEquals('1 qtr. ago', shortAlways.format(-1, 'quarter'));
assertEquals('in 0 qtrs.', shortAlways.format(0, 'quarter'));
373
assertEquals('0 qtrs. ago', shortAlways.format(-0, 'quarter'));
374 375
assertEquals('in 1 qtr.', shortAlways.format(1, 'quarter'));
assertEquals('in 2 qtrs.', shortAlways.format(2, 'quarter'));
376 377
assertEquals('in 345 qtrs.', shortAlways.format(345, 'quarter'));

378 379 380 381 382 383 384
assertEquals('3 yr. ago', shortAlways.format(-3, 'year'));
assertEquals('2 yr. ago', shortAlways.format(-2, 'year'));
assertEquals('1 yr. ago', shortAlways.format(-1, 'year'));
assertEquals('in 0 yr.', shortAlways.format(0, 'year'));
assertEquals('0 yr. ago', shortAlways.format(-0, 'year'));
assertEquals('in 1 yr.', shortAlways.format(1, 'year'));
assertEquals('in 2 yr.', shortAlways.format(2, 'year'));
385 386 387 388 389 390
assertEquals('in 345 yr.', shortAlways.format(345, 'year'));

// Somehow in the 'en' locale, there are no valeu for -narrow
let narrowAlways = new Intl.RelativeTimeFormat(
    "en", {style: "narrow", localeMatcher: 'lookup', numeric: 'always'});

391 392 393 394 395 396 397
assertEquals('3 sec. ago', narrowAlways.format(-3, 'second'));
assertEquals('2 sec. ago', narrowAlways.format(-2, 'second'));
assertEquals('1 sec. ago', narrowAlways.format(-1, 'second'));
assertEquals('in 0 sec.', narrowAlways.format(0, 'second'));
assertEquals('0 sec. ago', narrowAlways.format(-0, 'second'));
assertEquals('in 1 sec.', narrowAlways.format(1, 'second'));
assertEquals('in 2 sec.', narrowAlways.format(2, 'second'));
398 399
assertEquals('in 345 sec.', narrowAlways.format(345, 'second'));

400 401 402 403 404 405 406
assertEquals('3 min. ago', narrowAlways.format(-3, 'minute'));
assertEquals('2 min. ago', narrowAlways.format(-2, 'minute'));
assertEquals('1 min. ago', narrowAlways.format(-1, 'minute'));
assertEquals('in 0 min.', narrowAlways.format(0, 'minute'));
assertEquals('0 min. ago', narrowAlways.format(-0, 'minute'));
assertEquals('in 1 min.', narrowAlways.format(1, 'minute'));
assertEquals('in 2 min.', narrowAlways.format(2, 'minute'));
407 408
assertEquals('in 345 min.', narrowAlways.format(345, 'minute'));

409 410 411 412 413 414 415
assertEquals('3 hr. ago', narrowAlways.format(-3, 'hour'));
assertEquals('2 hr. ago', narrowAlways.format(-2, 'hour'));
assertEquals('1 hr. ago', narrowAlways.format(-1, 'hour'));
assertEquals('in 0 hr.', narrowAlways.format(0, 'hour'));
assertEquals('0 hr. ago', narrowAlways.format(-0, 'hour'));
assertEquals('in 1 hr.', narrowAlways.format(1, 'hour'));
assertEquals('in 2 hr.', narrowAlways.format(2, 'hour'));
416 417
assertEquals('in 345 hr.', narrowAlways.format(345, 'hour'));

418 419 420 421 422 423 424
assertEquals('3 days ago', narrowAlways.format(-3, 'day'));
assertEquals('2 days ago', narrowAlways.format(-2, 'day'));
assertEquals('1 day ago', narrowAlways.format(-1, 'day'));
assertEquals('in 0 days', narrowAlways.format(0, 'day'));
assertEquals('0 days ago', narrowAlways.format(-0, 'day'));
assertEquals('in 1 day', narrowAlways.format(1, 'day'));
assertEquals('in 2 days', narrowAlways.format(2, 'day'));
425 426
assertEquals('in 345 days', narrowAlways.format(345, 'day'));

427 428 429 430 431 432 433
assertEquals('3 wk. ago', narrowAlways.format(-3, 'week'));
assertEquals('2 wk. ago', narrowAlways.format(-2, 'week'));
assertEquals('1 wk. ago', narrowAlways.format(-1, 'week'));
assertEquals('in 0 wk.', narrowAlways.format(0, 'week'));
assertEquals('0 wk. ago', narrowAlways.format(-0, 'week'));
assertEquals('in 1 wk.', narrowAlways.format(1, 'week'));
assertEquals('in 2 wk.', narrowAlways.format(2, 'week'));
434 435
assertEquals('in 345 wk.', narrowAlways.format(345, 'week'));

436 437 438 439 440 441 442
assertEquals('3 mo. ago', narrowAlways.format(-3, 'month'));
assertEquals('2 mo. ago', narrowAlways.format(-2, 'month'));
assertEquals('1 mo. ago', narrowAlways.format(-1, 'month'));
assertEquals('in 0 mo.', narrowAlways.format(0, 'month'));
assertEquals('0 mo. ago', narrowAlways.format(-0, 'month'));
assertEquals('in 1 mo.', narrowAlways.format(1, 'month'));
assertEquals('in 2 mo.', narrowAlways.format(2, 'month'));
443 444
assertEquals('in 345 mo.', narrowAlways.format(345, 'month'));

445 446 447 448
assertEquals('3 qtrs. ago', narrowAlways.format(-3, 'quarter'));
assertEquals('2 qtrs. ago', narrowAlways.format(-2, 'quarter'));
assertEquals('1 qtr. ago', narrowAlways.format(-1, 'quarter'));
assertEquals('in 0 qtrs.', narrowAlways.format(0, 'quarter'));
449
assertEquals('0 qtrs. ago', narrowAlways.format(-0, 'quarter'));
450 451
assertEquals('in 1 qtr.', narrowAlways.format(1, 'quarter'));
assertEquals('in 2 qtrs.', narrowAlways.format(2, 'quarter'));
452 453
assertEquals('in 345 qtrs.', narrowAlways.format(345, 'quarter'));

454 455 456 457 458 459 460
assertEquals('3 yr. ago', narrowAlways.format(-3, 'year'));
assertEquals('2 yr. ago', narrowAlways.format(-2, 'year'));
assertEquals('1 yr. ago', narrowAlways.format(-1, 'year'));
assertEquals('in 0 yr.', narrowAlways.format(0, 'year'));
assertEquals('0 yr. ago', narrowAlways.format(-0, 'year'));
assertEquals('in 1 yr.', narrowAlways.format(1, 'year'));
assertEquals('in 2 yr.', narrowAlways.format(2, 'year'));
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
assertEquals('in 345 yr.', narrowAlways.format(345, 'year'));

var styleNumericCombinations = [
    longAuto, shortAuto, narrowAuto, longAlways,
    shortAlways, narrowAlways ];
var validUnits = [
    'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];

// Test these all throw RangeError
for (var i = 0; i < styleNumericCombinations.length; i++) {
  for (var j = 0; j < validUnits.length; j++) {
    assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j]),
        RangeError);
    assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j] + 's'),
        RangeError);
    assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j]),
        RangeError);
    assertThrows(() => styleNumericCombinations[i].format(NaN, validUnits[j] + 's'),
        RangeError);
  }
}