Skip to content

Commit e5b2e3d

Browse files
Remove utils from P2P-V2 and never use it again (#13104)
* chore: removed responsive root * chore: reverted old changes * chore: removed utils and never use it again in p2p-v2
1 parent 9e4adf7 commit e5b2e3d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/p2p-v2/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@deriv/api": "^1.0.0",
1717
"@deriv/integration": "^1.0.0",
1818
"@deriv/react-joyride": "^2.6.2",
19-
"@deriv/utils": "^1.0.0",
2019
"@sendbird/chat": "^4.9.7",
2120
"clsx": "^2.0.0",
2221
"i18next": "^22.4.6",

packages/p2p-v2/src/utils/time.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
import { toMoment } from '@deriv/utils';
1+
import moment from 'moment';
2+
3+
/**
4+
* Function that converts a numerical epoch value into a Moment instance
5+
*/
6+
export const epochToMoment = (epoch: number) => moment.unix(epoch).utc();
7+
8+
/**
9+
* Function that takes a primitive type and converts it into a Moment instance
10+
*/
11+
export const toMoment = (value?: moment.MomentInput): moment.Moment => {
12+
if (!value) return moment().utc(); // returns 'now' moment object
13+
if (moment.isMoment(value) && value.isValid() && value.isUTC()) return value; // returns if already a moment object
14+
if (typeof value === 'number') return epochToMoment(value); // returns epochToMoment() if not a date
15+
16+
if (/invalid/i.test(moment(value).toString())) {
17+
const todayMoment = moment();
18+
const daysInMonth = todayMoment.utc().daysInMonth();
19+
const valueAsNumber = moment.utc(value, 'DD MMM YYYY').valueOf() / (1000 * 60 * 60 * 24);
20+
return valueAsNumber > daysInMonth
21+
? moment.utc(todayMoment.add(value.valueOf(), 'd'), 'DD MMM YYYY')
22+
: moment.utc(value, 'DD MMM YYYY'); // returns target date
23+
}
24+
return moment.utc(value);
25+
};
226

327
/**
428
* return the number of days since the date specified

0 commit comments

Comments
 (0)