2020-07-11 15:12:16 +00:00
|
|
|
import * as moment from 'moment';
|
2020-06-05 09:22:14 +00:00
|
|
|
|
2020-08-25 17:52:07 +00:00
|
|
|
export function formatPercent(value: number, decimals = 3): string {
|
|
|
|
return value ? `${(value * 100).toFixed(decimals)}%` : '';
|
2020-06-02 11:05:16 +00:00
|
|
|
}
|
2020-06-04 17:47:44 +00:00
|
|
|
|
2020-07-11 15:13:27 +00:00
|
|
|
export function formatPrice(value: number): string {
|
2020-06-04 17:47:44 +00:00
|
|
|
return value ? value.toFixed(8) : '';
|
|
|
|
}
|
|
|
|
|
2020-09-01 05:51:03 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param ts Timestamp as number or date (in utc!!)
|
|
|
|
*/
|
2020-07-13 19:40:05 +00:00
|
|
|
export function timestampms(ts: number | Date): string {
|
2020-09-01 05:51:03 +00:00
|
|
|
return moment.utc(ts).format('YYYY-MM-DD HH:mm:ss');
|
2020-06-05 09:22:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 15:15:13 +00:00
|
|
|
export function timestampToDateString(ts: number): string {
|
|
|
|
return moment(ts).format('YYYY-MM-DD');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function dateStringToTimeRange(ts: string): string {
|
|
|
|
return ts.replace(/-/g, '');
|
|
|
|
}
|
|
|
|
|
2020-08-17 19:15:15 +00:00
|
|
|
export function timestampHour(ts: number | Date): number {
|
2020-09-01 05:51:03 +00:00
|
|
|
return moment.utc(ts).hour();
|
2020-08-17 19:15:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 17:47:44 +00:00
|
|
|
export default {
|
|
|
|
formatPrice,
|
|
|
|
formatPercent,
|
2020-06-05 09:22:14 +00:00
|
|
|
timestampms,
|
2020-07-11 15:15:13 +00:00
|
|
|
timestampToDateString,
|
|
|
|
dateStringToTimeRange,
|
2020-06-04 17:47:44 +00:00
|
|
|
};
|