Skip to content

Commit

Permalink
feat: support UTC timezone formatting (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
KalachevDev authored Mar 28, 2023
1 parent d4df45f commit 4a6f21f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dateTime/dateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
};

/**
Expand Down
9 changes: 9 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 4a6f21f

Please sign in to comment.