Skip to content

Commit

Permalink
Remove utils from P2P-V2 and never use it again (#13104)
Browse files Browse the repository at this point in the history
* chore: removed responsive root

* chore: reverted old changes

* chore: removed utils and never use it again in p2p-v2
  • Loading branch information
adrienne-deriv authored Jan 24, 2024
1 parent 9e4adf7 commit e5b2e3d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/p2p-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@deriv/api": "^1.0.0",
"@deriv/integration": "^1.0.0",
"@deriv/react-joyride": "^2.6.2",
"@deriv/utils": "^1.0.0",
"@sendbird/chat": "^4.9.7",
"clsx": "^2.0.0",
"i18next": "^22.4.6",
Expand Down
26 changes: 25 additions & 1 deletion packages/p2p-v2/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
import { toMoment } from '@deriv/utils';
import moment from 'moment';

/**
* Function that converts a numerical epoch value into a Moment instance
*/
export const epochToMoment = (epoch: number) => moment.unix(epoch).utc();

/**
* Function that takes a primitive type and converts it into a Moment instance
*/
export const toMoment = (value?: moment.MomentInput): moment.Moment => {
if (!value) return moment().utc(); // returns 'now' moment object
if (moment.isMoment(value) && value.isValid() && value.isUTC()) return value; // returns if already a moment object
if (typeof value === 'number') return epochToMoment(value); // returns epochToMoment() if not a date

if (/invalid/i.test(moment(value).toString())) {
const todayMoment = moment();
const daysInMonth = todayMoment.utc().daysInMonth();
const valueAsNumber = moment.utc(value, 'DD MMM YYYY').valueOf() / (1000 * 60 * 60 * 24);
return valueAsNumber > daysInMonth
? moment.utc(todayMoment.add(value.valueOf(), 'd'), 'DD MMM YYYY')
: moment.utc(value, 'DD MMM YYYY'); // returns target date
}
return moment.utc(value);
};

/**
* return the number of days since the date specified
Expand Down

1 comment on commit e5b2e3d

@vercel
Copy link

@vercel vercel bot commented on e5b2e3d Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app.binary.sx
deriv-app.vercel.app
deriv-app-git-master.binary.sx
binary.sx

Please sign in to comment.