mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-21 23:53:52 +00:00
add timestampmsOrNA entry
This commit is contained in:
parent
1ba38a38e1
commit
b8013367fe
|
@ -38,6 +38,15 @@ export function timestampms(ts: number | Date): string {
|
|||
return formatDate(toDate(ts), 'yyyy-MM-dd HH:mm:ss');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a timestamp / Date object to String.
|
||||
* Returns 'N/A' if ts is null
|
||||
* @param ts Timestamp as number or date (in utc!!)
|
||||
*/
|
||||
export function timestampmsOrNa(ts: number | Date | null): string {
|
||||
return ts ? formatDate(toDate(ts), 'yyyy-MM-dd HH:mm:ss') : 'N/A';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a timestamp / Date object to String
|
||||
* @param ts Timestamp as number or date (in utc!!)
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
dateStringToTimeRange,
|
||||
timestampHour,
|
||||
dateFromString,
|
||||
timestampmsOrNa,
|
||||
} from '@/shared/formatters';
|
||||
|
||||
const { getTimeZone } = exportForTesting;
|
||||
|
@ -38,6 +39,16 @@ describe('timeformatter.ts', () => {
|
|||
setTimezone('CET');
|
||||
expect(timestampms(1651057500000)).toEqual('2022-04-27 13:05:00');
|
||||
});
|
||||
|
||||
it('timestampmsOrNA convert correctly', () => {
|
||||
setTimezone('UTC');
|
||||
expect(timestampmsOrNa(1651057500000)).toEqual('2022-04-27 11:05:00');
|
||||
setTimezone('CET');
|
||||
expect(timestampmsOrNa(1651057500000)).toEqual('2022-04-27 13:05:00');
|
||||
|
||||
expect(timestampmsOrNa(0)).toEqual('N/A');
|
||||
expect(timestampmsOrNa(null)).toEqual('N/A');
|
||||
});
|
||||
it('timestampToDateString converts to date', () => {
|
||||
expect(timestampToDateString(1651057500000)).toEqual('2022-04-27');
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user