Skip to content

Commit

Permalink
fix: revert support UTC formatting (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
korvin89 authored Apr 7, 2023
1 parent be1aad1 commit be2d98c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
22 changes: 22 additions & 0 deletions src/dateTime/dateTime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import MockDate from 'mockdate';
import {DEFAULT_SYSTEM_DATE_FORMAT} from '../constants';
import {settings} from '../settings';
import {dateTime, isDateTime} from './dateTime';
import type {DurationUnit} from '../typings';

const MOCKED_DATE = '2021-08-07T12:10:00';

MockDate.set(MOCKED_DATE);

afterEach(() => {
MockDate.set(MOCKED_DATE);
});

describe('DateTime', () => {
const TESTED_DATE_STRING = '2021-08-07';

Expand Down Expand Up @@ -74,5 +79,22 @@ describe('DateTime', () => {
expect(date.minute()).toEqual(10);
expect(date.hour()).toEqual(10);
});

test.each<[{amount: string; unit: DurationUnit; durationUnit: DurationUnit}, string]>([
[{amount: '-24', unit: 'h', durationUnit: 'm'}, '2020-02-13T22:34:59.999Z'],
[{amount: '-300', unit: 's', durationUnit: 's'}, '2020-02-14T22:29:55.999Z'],
])('endOf (%j)', ({amount, unit, durationUnit}, expected) => {
MockDate.set('2020-02-14T22:34:55.359Z');
const date = dateTime({timeZone: 'UTC'}).add(amount, unit).endOf(durationUnit);
expect(date.toISOString()).toEqual(expected);
});

test.each<[{amount: string; unit: DurationUnit; durationUnit: DurationUnit}, string]>([
[{amount: '+60', unit: 'm', durationUnit: 's'}, '2020-02-14T23:34:55.000Z'],
])('startOf (%j)', ({amount, unit, durationUnit}, expected) => {
MockDate.set('2020-02-14T22:34:55.359Z');
const date = dateTime({timeZone: 'UTC'}).add(amount, unit).startOf(durationUnit);
expect(date.toISOString()).toEqual(expected);
});
});
});
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)
).tz('UTC') as DateTime; // setting .tz('UTC') allows having .format('L z') -> `02/02/2000 UTC`
) as DateTime;
};

/**
Expand Down
9 changes: 0 additions & 9 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,4 @@ 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 be2d98c

Please sign in to comment.