vega-frontend-monorepo/libs/react-helpers/src/lib/format/date.ts
Matthew Russell d5727baffc
fix(#623): order fixes
* feat: format size and volume with positionDecimalPlaces

* fix: pass in calculated step so client side validation works

* fix: add requested state to order dialog, handle user rejected error

* feat: add test case for user rejecting tx

* feat: add test case for order list fractional sizes

* feat: add test case for fractional volume in positions table

* fix: deal ticket tests imports

* feat: add test case for trades fractional size

* fix: props for orderbook tests

* fix: add missing positionDecimalPlaces fields to mock functions

* fix: improve error handling of service error with type guard
2022-06-23 15:00:58 -07:00

51 lines
1.2 KiB
TypeScript

import once from 'lodash/once';
import { getUserLocale } from './utils';
export const getTimeFormat = once(
() =>
new Intl.DateTimeFormat(getUserLocale(), {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
})
);
export const getDateFormat = once(
() =>
new Intl.DateTimeFormat(getUserLocale(), {
year: 'numeric',
month: 'numeric',
day: 'numeric',
})
);
export const getDateTimeFormat = once(
() =>
new Intl.DateTimeFormat(getUserLocale(), {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
})
);
export const getRelativeTimeFormat = once(
() => new Intl.RelativeTimeFormat(getUserLocale())
);
/** Returns date in a format suitable for input[type=date] elements */
export const formatForInput = (date: Date) => {
const padZero = (num: number) => num.toString().padStart(2, '0');
const year = date.getFullYear();
const month = padZero(date.getMonth() + 1);
const day = padZero(date.getDate());
const hours = padZero(date.getHours());
const minutes = padZero(date.getMinutes());
const secs = padZero(date.getSeconds());
return `${year}-${month}-${day}T${hours}:${minutes}:${secs}`;
};