From 816965affd04457ce6930ade46d8103a83dbd590 Mon Sep 17 00:00:00 2001 From: Vladimir Kalachev Date: Tue, 28 Mar 2023 14:38:43 +0300 Subject: [PATCH] feat: support UTC timezone formatting --- src/dateTime/dateTime.ts | 2 +- src/index.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/dateTime/dateTime.ts b/src/dateTime/dateTime.ts index 206c1ee..c9ec548 100644 --- a/src/dateTime/dateTime.ts +++ b/src/dateTime/dateTime.ts @@ -18,7 +18,7 @@ export const createDateTime = ( export const createUTCDateTime = (input?: DateTimeInput, format?: FormatInput) => { return ( format ? dayjs.utc(input as ConfigType, format, STRICT) : dayjs.utc(input as ConfigType) - ) as DateTime; + ).tz('UTC') as DateTime; // setting .tz('UTC') allows having .format('L z') -> `02/02/2000 UTC` }; /** diff --git a/src/index.test.ts b/src/index.test.ts index 6321c7e..d095417 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -71,4 +71,13 @@ describe('Public API', () => { expect(timezone).toBe('Greenwich'); }); + + it('utc timezone is supported', () => { + const dateWithTimezone = dateTime({ + input: '2000-02-02T00:00:00.001Z', + timeZone: 'utc', + }); + + expect(dateWithTimezone.format('L z')).toBe('02/02/2000 UTC'); + }); });