Sitelet https://github.com/angular/angular/commit/feda78e
Skip to content

Commit feda78e

Browse files
AndrewKushnirjosephperrott
authored andcommitted
fix(common): change the week-numbering year format from r -> Y (#39495)
This commit updates the week-numbering year format from `r` -> `Y` based on the description in http://www.unicode.org/reports/tr35/tr35-dates.html#dfst-year. Note: this is not a breaking change, since the week-numbering year format was introduced in v11.0.0-next.3 (984ed39) and the major version that contains that change was not released yet. PR Close #39495
1 parent 3091534 commit feda78e

3 files changed

Lines changed: 21 additions & 21 deletions

File tree

‎packages/common/src/i18n/format_date.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const ISO8601_DATE_REGEX =
1313
// 1 2 3 4 5 6 7 8 9 10 11
1414
const NAMED_FORMATS: {[localeId: string]: {[format: string]: string}} = {};
1515
const DATE_FORMATS_SPLIT =
16-
/((?:[^GyrMLwWdEabBhHmsSzZO']+)|(?:'(?:[^']|'')*')|(?:G{1,5}|y{1,4}|r{1,4}|M{1,5}|L{1,5}|w{1,2}|W{1}|d{1,2}|E{1,6}|a{1,5}|b{1,5}|B{1,5}|h{1,2}|H{1,2}|m{1,2}|s{1,2}|S{1,3}|z{1,4}|Z{1,5}|O{1,4}))([\s\S]*)/;
16+
/((?:[^GyYMLwWdEabBhHmsSzZO']+)|(?:'(?:[^']|'')*')|(?:G{1,5}|y{1,4}|Y{1,4}|M{1,5}|L{1,5}|w{1,2}|W{1}|d{1,2}|E{1,6}|a{1,5}|b{1,5}|B{1,5}|h{1,2}|H{1,2}|m{1,2}|s{1,2}|S{1,3}|z{1,4}|Z{1,5}|O{1,4}))([\s\S]*)/;
1717

1818
enum ZoneWidth {
1919
Short,
@@ -451,21 +451,21 @@ function getDateFormatter(format: string): DateFormatter|null {
451451
break;
452452

453453
// 1 digit representation of the week-numbering year, e.g. (AD 1 => 1, AD 199 => 199)
454-
case 'r':
454+
case 'Y':
455455
formatter = weekNumberingYearGetter(1);
456456
break;
457457
// 2 digit representation of the week-numbering year, padded (00-99). (e.g. AD 2001 => 01, AD
458458
// 2010 => 10)
459-
case 'rr':
459+
case 'YY':
460460
formatter = weekNumberingYearGetter(2, true);
461461
break;
462462
// 3 digit representation of the week-numbering year, padded (000-999). (e.g. AD 1 => 001, AD
463463
// 2010 => 2010)
464-
case 'rrr':
464+
case 'YYY':
465465
formatter = weekNumberingYearGetter(3);
466466
break;
467467
// 4 digit representation of the week-numbering year (e.g. AD 1 => 0001, AD 2010 => 2010)
468-
case 'rrrr':
468+
case 'YYYY':
469469
formatter = weekNumberingYearGetter(4);
470470
break;
471471

‎packages/common/src/pipes/date_pipe.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
6565
* | | yy | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
6666
* | | yyy | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
6767
* | | yyyy | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
68-
* | Week-numbering year| r | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
69-
* | | rr | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
70-
* | | rrr | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
71-
* | | rrrr | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
68+
* | Week-numbering year| Y | Numeric: minimum digits | 2, 20, 201, 2017, 20173 |
69+
* | | YY | Numeric: 2 digits + zero padded | 02, 20, 01, 17, 73 |
70+
* | | YYY | Numeric: 3 digits + zero padded | 002, 020, 201, 2017, 20173 |
71+
* | | YYYY | Numeric: 4 digits or more + zero padded | 0002, 0020, 0201, 2017, 20173 |
7272
* | Month | M | Numeric: 1 digit | 9, 12 |
7373
* | | MM | Numeric: 2 digits + zero padded | 09, 12 |
7474
* | | MMM | Abbreviated | Sep |

‎packages/common/test/i18n/format_date_spec.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ describe('Format date', () => {
9595
yy: '15',
9696
yyy: '2015',
9797
yyyy: '2015',
98-
r: '2015',
99-
rr: '15',
100-
rrr: '2015',
101-
rrrr: '2015',
98+
Y: '2015',
99+
YY: '15',
100+
YYY: '2015',
101+
YYYY: '2015',
102102
M: '6',
103103
MM: '06',
104104
MMM: 'Jun',
@@ -157,10 +157,10 @@ describe('Format date', () => {
157157
yy: '15',
158158
yyy: '2015',
159159
yyyy: '2015',
160-
r: '2015',
161-
rr: '15',
162-
rrr: '2015',
163-
rrrr: '2015',
160+
Y: '2015',
161+
YY: '15',
162+
YYY: '2015',
163+
YYYY: '2015',
164164
M: '1',
165165
MM: '01',
166166
MMM: 'Jan',
@@ -373,10 +373,10 @@ describe('Format date', () => {
373373
// https://github.com/angular/angular/issues/38739
374374
it('should return correct ISO 8601 week-numbering year for dates close to year end/beginning',
375375
() => {
376-
expect(formatDate('2013-12-27', 'rrrr', 'en')).toEqual('2013');
377-
expect(formatDate('2013-12-29', 'rrrr', 'en')).toEqual('2014');
378-
expect(formatDate('2010-01-02', 'rrrr', 'en')).toEqual('2009');
379-
expect(formatDate('2010-01-04', 'rrrr', 'en')).toEqual('2010');
376+
expect(formatDate('2013-12-27', 'YYYY', 'en')).toEqual('2013');
377+
expect(formatDate('2013-12-29', 'YYYY', 'en')).toEqual('2014');
378+
expect(formatDate('2010-01-02', 'YYYY', 'en')).toEqual('2009');
379+
expect(formatDate('2010-01-04', 'YYYY', 'en')).toEqual('2010');
380380
});
381381
});
382382
});

0 commit comments

Comments
 (0)