mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 10:21:55 +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');
|
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
|
* Convert a timestamp / Date object to String
|
||||||
* @param ts Timestamp as number or date (in utc!!)
|
* @param ts Timestamp as number or date (in utc!!)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
dateStringToTimeRange,
|
dateStringToTimeRange,
|
||||||
timestampHour,
|
timestampHour,
|
||||||
dateFromString,
|
dateFromString,
|
||||||
|
timestampmsOrNa,
|
||||||
} from '@/shared/formatters';
|
} from '@/shared/formatters';
|
||||||
|
|
||||||
const { getTimeZone } = exportForTesting;
|
const { getTimeZone } = exportForTesting;
|
||||||
|
@ -38,6 +39,16 @@ describe('timeformatter.ts', () => {
|
||||||
setTimezone('CET');
|
setTimezone('CET');
|
||||||
expect(timestampms(1651057500000)).toEqual('2022-04-27 13:05:00');
|
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', () => {
|
it('timestampToDateString converts to date', () => {
|
||||||
expect(timestampToDateString(1651057500000)).toEqual('2022-04-27');
|
expect(timestampToDateString(1651057500000)).toEqual('2022-04-27');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user