parent
a005d1595e
commit
f29457f3f0
@ -64,6 +64,7 @@ export function main() {
|
|||||||
expect(pipe.transform(date, 's')).toEqual('1');
|
expect(pipe.transform(date, 's')).toEqual('1');
|
||||||
expect(pipe.transform(date, 'mm')).toEqual('03');
|
expect(pipe.transform(date, 'mm')).toEqual('03');
|
||||||
expect(pipe.transform(date, 'ss')).toEqual('01');
|
expect(pipe.transform(date, 'ss')).toEqual('01');
|
||||||
|
expect(pipe.transform(date, 'Z')).toEqual('GMT');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should format common multi component patterns', () => {
|
it('should format common multi component patterns', () => {
|
||||||
|
@ -37,7 +37,7 @@ export class NumberFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var DATE_FORMATS_SPLIT =
|
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 = {
|
var PATTERN_ALIASES = {
|
||||||
yMMMdjms: datePartGetterFactory(combine([
|
yMMMdjms: datePartGetterFactory(combine([
|
||||||
@ -99,8 +99,8 @@ var DATE_FORMATS = {
|
|||||||
EE: datePartGetterFactory(nameCondition('weekday', 2)),
|
EE: datePartGetterFactory(nameCondition('weekday', 2)),
|
||||||
E: datePartGetterFactory(nameCondition('weekday', 1)),
|
E: datePartGetterFactory(nameCondition('weekday', 1)),
|
||||||
a: hourClockExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
|
a: hourClockExtracter(datePartGetterFactory(hour12Modify(digitCondition('hour', 1), true))),
|
||||||
Z: datePartGetterFactory({timeZoneName: 'long'}),
|
Z: timeZoneGetter('short'),
|
||||||
z: datePartGetterFactory({timeZoneName: 'short'}),
|
z: timeZoneGetter('long'),
|
||||||
ww: datePartGetterFactory({}), // Week of year, padded (00-53). Week 01 is the week with the
|
ww: datePartGetterFactory({}), // Week of year, padded (00-53). Week 01 is the week with the
|
||||||
// first Thursday of the year. not support ?
|
// first Thursday of the year. not support ?
|
||||||
w: datePartGetterFactory({}), // Week of year (0-53). Week 1 is the week with the first Thursday
|
w: datePartGetterFactory({}), // Week of year (0-53). Week 1 is the week with the first Thursday
|
||||||
@ -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(
|
function hour12Modify(
|
||||||
options: Intl.DateTimeFormatOptions, value: boolean): Intl.DateTimeFormatOptions {
|
options: Intl.DateTimeFormatOptions, value: boolean): Intl.DateTimeFormatOptions {
|
||||||
options.hour12 = value;
|
options.hour12 = value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user