fix: 1842 set expiry to date time format (#1866)
* fix: #1842 set expiry to date time format * fix: #1842 consistent expiry date time
This commit is contained in:
parent
0be668ae86
commit
b273e2740d
@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { MarketExpires } from './market-expires';
|
||||
|
||||
describe('MarketExpires', () => {
|
||||
@ -13,7 +14,7 @@ describe('MarketExpires', () => {
|
||||
'settlement:20220525T1200',
|
||||
];
|
||||
render(<MarketExpires tags={tags} />);
|
||||
expect(screen.getByText('May 25')).toBeInTheDocument();
|
||||
expect(screen.getByText('25/05/2022, 12:00:00')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('settlement-date:date', () => {
|
||||
@ -23,7 +24,7 @@ describe('MarketExpires', () => {
|
||||
'settlement-date:2022-04-25T1200',
|
||||
];
|
||||
render(<MarketExpires tags={tags} />);
|
||||
expect(screen.getByText('Apr 25')).toBeInTheDocument();
|
||||
expect(screen.getByText('25/04/2022, 12:00:00')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('last one proper tag should matter', () => {
|
||||
@ -33,7 +34,7 @@ describe('MarketExpires', () => {
|
||||
'settlement-expiry-date:2022-03-25T12:00:00',
|
||||
];
|
||||
render(<MarketExpires tags={tags} />);
|
||||
expect(screen.getByText('Mar 25')).toBeInTheDocument();
|
||||
expect(screen.getByText('25/03/2022, 12:00:00')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('when no proper tag nor date should be null', () => {
|
||||
|
@ -1,8 +1,7 @@
|
||||
import type { SingleMarketFieldsFragment } from '@vegaprotocol/market-list';
|
||||
import { getDateFormat, t } from '@vegaprotocol/react-helpers';
|
||||
import { format, isValid, parseISO } from 'date-fns';
|
||||
import { getDateTimeFormat, t } from '@vegaprotocol/react-helpers';
|
||||
import { isValid, parseISO } from 'date-fns';
|
||||
|
||||
export const EXPIRE_DATE_FORMAT = 'MMM dd';
|
||||
import type { SingleMarketFieldsFragment } from '@vegaprotocol/market-list';
|
||||
|
||||
export const getMarketExpiryDate = (
|
||||
tags?: ReadonlyArray<string> | null
|
||||
@ -31,7 +30,7 @@ export const getMarketExpiryDateFormatted = (
|
||||
): string | null => {
|
||||
if (tags) {
|
||||
const dateFound = getMarketExpiryDate(tags);
|
||||
return dateFound ? format(dateFound, EXPIRE_DATE_FORMAT) : null;
|
||||
return dateFound ? getDateTimeFormat().format(dateFound) : null;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@ -45,14 +44,14 @@ export const getExpiryDate = (market: SingleMarketFieldsFragment): string => {
|
||||
let content = null;
|
||||
if (!closeDate) {
|
||||
content = closedMarketDate
|
||||
? `Expired on ${getDateFormat().format(closedMarketDate)}`
|
||||
? `Expired on ${getDateTimeFormat().format(closedMarketDate)}`
|
||||
: t('Not time-based');
|
||||
} else {
|
||||
const isExpired = Date.now() - closeDate.valueOf() > 0;
|
||||
const expiryDate = getDateFormat().format(closeDate);
|
||||
const expiryDate = getDateTimeFormat().format(closeDate);
|
||||
if (isExpired) {
|
||||
content = closedMarketDate
|
||||
? `Expired on ${getDateFormat().format(closedMarketDate)}`
|
||||
? `Expired on ${getDateTimeFormat().format(closedMarketDate)}`
|
||||
: t('Expired');
|
||||
} else {
|
||||
content = expiryDate;
|
||||
|
Loading…
Reference in New Issue
Block a user