Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/@angular/common/test/pipes/date_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function main() {
expect(pipe.transform(date, 's')).toEqual('1');
expect(pipe.transform(date, 'mm')).toEqual('03');
expect(pipe.transform(date, 'ss')).toEqual('01');
expect(pipe.transform(date, 'Z')).toEqual('GMT');
});

it('should format common multi component patterns', () => {
Expand Down
16 changes: 13 additions & 3 deletions modules/@angular/facade/src/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class NumberFormatter {
}
}
var DATE_FORMATS_SPLIT =
/((?:[^yMLdHhmsaZEwGjJ']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|J+|j+|m+|s+|a|Z|G+|w+))(.*)/;
/((?:[^yMLdHhmsazZEwGjJ']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|J+|j+|m+|s+|a|z|Z|G+|w+))(.*)/;

var PATTERN_ALIASES = {
yMMMdjms: datePartGetterFactory(combine([
Expand Down Expand Up @@ -99,8 +99,8 @@ var DATE_FORMATS = {
EE: datePartGetterFactory(nameCondition('weekday', 2)),
E: datePartGetterFactory(nameCondition('weekday', 1)),
a: hourClockExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
Z: datePartGetterFactory({timeZoneName: 'long'}),
z: datePartGetterFactory({timeZoneName: 'short'}),
Z: timeZoneGetter('short'),
z: timeZoneGetter('long'),
ww: datePartGetterFactory({}), // Week of year, padded (00-53). Week 01 is the week with the
// first Thursday of the year. not support ?
w: datePartGetterFactory({}), // Week of year (0-53). Week 1 is the week with the first Thursday
Expand Down Expand Up @@ -139,6 +139,16 @@ function hourExtracter(inner: (date: Date, locale: string) => string): (
};
}

function timeZoneGetter(timezone: string): (date: Date, locale: string) => string {
// To workaround `Intl` API restriction for single timezone let format with 24 hours
const format = {hour: '2-digit', hour12: false, timeZoneName: timezone};
return function(date: Date, locale: string): string {
const result = new Intl.DateTimeFormat(locale, format).format(date);
// Then extract first 3 letters that related to hours
return result ? result.substring(3) : '';
};
}

function hour12Modify(
options: Intl.DateTimeFormatOptions, value: boolean): Intl.DateTimeFormatOptions {
options.hour12 = value;
Expand Down