|
1 | | -import { load, cldr, localeInfo, dateFormatNames, firstDay, localeCurrency, currencyDisplay, currencyFractionOptions, currencyDisplays, numberSymbols } from '../src/cldr'; |
| 1 | +import { load, cldr, localeInfo, dateFieldName, dateFormatNames, firstDay, localeCurrency, currencyDisplay, currencyFractionOptions, currencyDisplays, numberSymbols } from '../src/cldr'; |
2 | 2 | import { errors } from '../src/errors'; |
3 | 3 |
|
4 | 4 | const likelySubtags = require("cldr-data/supplemental/likelySubtags.json"); |
@@ -366,6 +366,120 @@ describe('dateFormatNames', () => { |
366 | 366 | }); |
367 | 367 | }); |
368 | 368 |
|
| 369 | +describe('dateFieldName', () => { |
| 370 | + it('should return placeholder for the era type', () => { |
| 371 | + expect(dateFieldName({ type: 'era', nameType: 'wide' })).toEqual("era"); |
| 372 | + expect(dateFieldName({ type: 'era', nameType: 'narrow' })).toEqual("era"); |
| 373 | + expect(dateFieldName({ type: 'era', nameType: 'short' })).toEqual("era"); |
| 374 | + }); |
| 375 | + |
| 376 | + it('should return placeholder for the year type', () => { |
| 377 | + expect(dateFieldName({ type: 'year', nameType: 'wide' })).toEqual("year"); |
| 378 | + expect(dateFieldName({ type: 'year', nameType: 'narrow' })).toEqual("yr."); |
| 379 | + expect(dateFieldName({ type: 'year', nameType: 'short' })).toEqual("yr."); |
| 380 | + }); |
| 381 | + |
| 382 | + it('should return placeholder for the quarter type', () => { |
| 383 | + expect(dateFieldName({ type: 'quarter', nameType: 'wide' })).toEqual("quarter"); |
| 384 | + expect(dateFieldName({ type: 'quarter', nameType: 'narrow' })).toEqual("qtr."); |
| 385 | + expect(dateFieldName({ type: 'quarter', nameType: 'short' })).toEqual("qtr."); |
| 386 | + }); |
| 387 | + |
| 388 | + it('should return placeholder for the month type', () => { |
| 389 | + expect(dateFieldName({ type: 'month', nameType: 'wide' })).toEqual("month"); |
| 390 | + expect(dateFieldName({ type: 'month', nameType: 'narrow' })).toEqual("mo."); |
| 391 | + expect(dateFieldName({ type: 'month', nameType: 'short' })).toEqual("mo."); |
| 392 | + }); |
| 393 | + |
| 394 | + it('should return placeholder for the month type', () => { |
| 395 | + expect(dateFieldName({ type: 'month', nameType: 'wide' })).toEqual("month"); |
| 396 | + expect(dateFieldName({ type: 'month', nameType: 'narrow' })).toEqual("mo."); |
| 397 | + expect(dateFieldName({ type: 'month', nameType: 'short' })).toEqual("mo."); |
| 398 | + }); |
| 399 | + |
| 400 | + it('should return placeholder for the week type', () => { |
| 401 | + expect(dateFieldName({ type: 'week', nameType: 'wide' })).toEqual("week"); |
| 402 | + expect(dateFieldName({ type: 'week', nameType: 'narrow' })).toEqual("wk."); |
| 403 | + expect(dateFieldName({ type: 'week', nameType: 'short' })).toEqual("wk."); |
| 404 | + }); |
| 405 | + |
| 406 | + it('should return placeholder for the day type', () => { |
| 407 | + expect(dateFieldName({ type: 'day', nameType: 'wide' })).toEqual("day"); |
| 408 | + expect(dateFieldName({ type: 'day', nameType: 'narrow' })).toEqual("day"); |
| 409 | + expect(dateFieldName({ type: 'day', nameType: 'short' })).toEqual("day"); |
| 410 | + }); |
| 411 | + |
| 412 | + it('should return localized placeholder for the day type', () => { |
| 413 | + expect(dateFieldName({ type: 'day', nameType: 'wide' }, 'bg')).toEqual("ден"); |
| 414 | + expect(dateFieldName({ type: 'day', nameType: 'narrow' }, 'bg')).toEqual("д"); |
| 415 | + expect(dateFieldName({ type: 'day', nameType: 'short' }, 'bg')).toEqual("д"); |
| 416 | + }); |
| 417 | + |
| 418 | + it('should return placeholder for the weekday type', () => { |
| 419 | + expect(dateFieldName({ type: 'weekday', nameType: 'wide' })).toEqual("day of the week"); |
| 420 | + expect(dateFieldName({ type: 'weekday', nameType: 'narrow' })).toEqual("day of the week"); |
| 421 | + expect(dateFieldName({ type: 'weekday', nameType: 'short' })).toEqual("day of the week"); |
| 422 | + }); |
| 423 | + |
| 424 | + it('should return localized placeholder for the weekday type', () => { |
| 425 | + expect(dateFieldName({ type: 'weekday', nameType: 'wide' }, 'bg')).toEqual("ден от седмицата"); |
| 426 | + expect(dateFieldName({ type: 'weekday', nameType: 'narrow' }, 'bg')).toEqual("ден от седмицата"); |
| 427 | + expect(dateFieldName({ type: 'weekday', nameType: 'short' }, 'bg')).toEqual("ден от седмицата"); |
| 428 | + }); |
| 429 | + |
| 430 | + it('should return placeholder for the dayperiod type', () => { |
| 431 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'wide' })).toEqual("AM/PM"); |
| 432 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'narrow' })).toEqual("AM/PM"); |
| 433 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'short' })).toEqual("AM/PM"); |
| 434 | + }); |
| 435 | + |
| 436 | + it('should return localized placeholder for the dayperiod type', () => { |
| 437 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'wide' }, 'bg')).toEqual("пр.об./сл.об."); |
| 438 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'narrow' }, 'bg')).toEqual("пр.об./сл.об."); |
| 439 | + expect(dateFieldName({ type: 'dayperiod', nameType: 'short' }, 'bg')).toEqual("пр.об./сл.об."); |
| 440 | + }); |
| 441 | + |
| 442 | + it('should return placeholder for hour type', () => { |
| 443 | + expect(dateFieldName({ type: 'hour', nameType: 'wide' })).toEqual("hour"); |
| 444 | + expect(dateFieldName({ type: 'hour', nameType: 'narrow' })).toEqual("hr."); |
| 445 | + expect(dateFieldName({ type: 'hour', nameType: 'short' })).toEqual("hr."); |
| 446 | + }); |
| 447 | + |
| 448 | + it('should return localized placeholder for hour type', () => { |
| 449 | + expect(dateFieldName({ type: 'hour', nameType: 'wide' }, 'bg')).toEqual("час"); |
| 450 | + expect(dateFieldName({ type: 'hour', nameType: 'narrow' }, 'bg')).toEqual("ч"); |
| 451 | + expect(dateFieldName({ type: 'hour', nameType: 'short' }, 'bg')).toEqual("ч"); |
| 452 | + }); |
| 453 | + |
| 454 | + it('should return placeholder for minute type', () => { |
| 455 | + expect(dateFieldName({ type: 'minute', nameType: 'wide' })).toEqual("minute"); |
| 456 | + expect(dateFieldName({ type: 'minute', nameType: 'narrow' })).toEqual("min."); |
| 457 | + expect(dateFieldName({ type: 'minute', nameType: 'short' })).toEqual("min."); |
| 458 | + }); |
| 459 | + |
| 460 | + it('should return placeholder for second type', () => { |
| 461 | + expect(dateFieldName({ type: 'second', nameType: 'wide' })).toEqual("second"); |
| 462 | + expect(dateFieldName({ type: 'second', nameType: 'narrow' })).toEqual("sec."); |
| 463 | + expect(dateFieldName({ type: 'second', nameType: 'short' })).toEqual("sec."); |
| 464 | + }); |
| 465 | + |
| 466 | + it('should return placeholder for zone type', () => { |
| 467 | + expect(dateFieldName({ type: 'zone', nameType: 'wide' })).toEqual("time zone"); |
| 468 | + expect(dateFieldName({ type: 'zone', nameType: 'narrow' })).toEqual("time zone"); |
| 469 | + expect(dateFieldName({ type: 'zone', nameType: 'short' })).toEqual("time zone"); |
| 470 | + }); |
| 471 | + |
| 472 | + it('should return undefined for missing fieldName type', () => { |
| 473 | + expect(dateFieldName({ type: 'millisecond', nameType: 'wide' })).toEqual(undefined); |
| 474 | + expect(dateFieldName({ type: 'millisecond', nameType: 'narrow' })).toEqual(undefined); |
| 475 | + expect(dateFieldName({ type: 'millisecond', nameType: 'short' })).toEqual(undefined); |
| 476 | + }); |
| 477 | + |
| 478 | + it('should return wide placeholder by default', () => { |
| 479 | + expect(dateFieldName({ type: 'year' })).toEqual('year'); |
| 480 | + }); |
| 481 | +}); |
| 482 | + |
369 | 483 | describe('firstDay', () => { |
370 | 484 | it('should return first day name based on locale', () => { |
371 | 485 | expect(firstDay('en')).toBe(0); |
|
0 commit comments