mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-24 20:15:15 +00:00
Add tests for timeformat "parseDate"
This commit is contained in:
parent
9984052688
commit
fabe44293e
|
@ -1,10 +1,12 @@
|
|||
import { parse, toDate } from 'date-fns';
|
||||
import { format, utcToZonedTime } from 'date-fns-tz';
|
||||
import { format, utcToZonedTime, zonedTimeToUtc } from 'date-fns-tz';
|
||||
import humanizeDuration from 'humanize-duration';
|
||||
import { isUndefined } from './numberformat';
|
||||
|
||||
/** Parse date from string, returns date in UTC! */
|
||||
export function dateFromString(datestring: string, format: string): Date {
|
||||
return parse(datestring, format, 0);
|
||||
const localTime = parse(datestring, format, 0);
|
||||
return zonedTimeToUtc(localTime, 'UTC');
|
||||
}
|
||||
|
||||
let locTimeZone = 'UTC';
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
timestampToDateString,
|
||||
dateStringToTimeRange,
|
||||
timestampHour,
|
||||
dateFromString,
|
||||
} from '@/shared/formatters';
|
||||
|
||||
const { getTimeZone } = exportForTesting;
|
||||
|
@ -58,4 +59,15 @@ describe('timeformatter.ts', () => {
|
|||
setTimezone('CET');
|
||||
expect(timestampHour(1651057500000)).toEqual(13);
|
||||
});
|
||||
it('dateFromString converts correctly', () => {
|
||||
expect(dateFromString('2022-04-04', 'yyyy-MM-dd')).toEqual(
|
||||
new Date('2022-04-04T00:00:00.000Z'),
|
||||
);
|
||||
expect(dateFromString('2023-02-08', 'yyyy-MM-dd')).toEqual(
|
||||
new Date('2023-02-08T00:00:00.000Z'),
|
||||
);
|
||||
expect(dateFromString('2022-12-31', 'yyyy-MM-dd')).toEqual(
|
||||
new Date('2022-12-31T00:00:00.000Z'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user