mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-29897 Add timezone as adfLocalizedDate pipe argument to allow to remove timezone-specific shifts (#10541)
This commit is contained in:
@@ -65,4 +65,20 @@ describe('LocalizedDatePipe', () => {
|
||||
const format = 'longDate';
|
||||
expect(pipe.transform(date, format, locale)).toBe('3 juillet 1990');
|
||||
});
|
||||
|
||||
it("should return the previous day's date when local timezone has a negative offset", () => {
|
||||
const date = new Date('2025-01-09T00:00:00.000Z');
|
||||
const locale = 'en-US';
|
||||
const format = 'mediumDate';
|
||||
const timezone = 'UTC-6';
|
||||
expect(pipe.transform(date, format, locale, timezone)).toBe('Jan 8, 2025');
|
||||
});
|
||||
|
||||
it('should return the provided date when local timezone is set to UTC', () => {
|
||||
const date = new Date('2025-01-09T00:00:00.000Z');
|
||||
const locale = 'en-US';
|
||||
const format = 'mediumDate';
|
||||
const timezone = 'UTC';
|
||||
expect(pipe.transform(date, format, locale, timezone)).toBe('Jan 9, 2025');
|
||||
});
|
||||
});
|
||||
|
@@ -53,10 +53,10 @@ export class LocalizedDatePipe implements PipeTransform, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
transform(value: Date | string | number, format?: string, locale?: string): string {
|
||||
transform(value: Date | string | number, format?: string, locale?: string, timezone?: string): string {
|
||||
const actualFormat = format || this.defaultFormat;
|
||||
const actualLocale = locale || this.defaultLocale;
|
||||
const datePipe = new DatePipe(actualLocale);
|
||||
const datePipe = timezone ? new DatePipe(actualLocale, timezone) : new DatePipe(actualLocale);
|
||||
return datePipe.transform(value, actualFormat);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user