From 1d3b534902f7c72f8223a62235f2cb89b2ffa852 Mon Sep 17 00:00:00 2001 From: John Coburn Date: Fri, 5 Jan 2024 15:00:36 -0600 Subject: [PATCH 1/2] replace moment calls with dayjs --- lib/ChangeDueDateDialog/ChangeDueDate.js | 11 +++++------ lib/ChangeDueDateDialog/DueDatePicker.js | 5 ++--- lib/ProxyManager/proxyUtil.js | 6 +++--- .../components/DateRangeFilter/date-validations.js | 12 ++++++------ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/ChangeDueDateDialog/ChangeDueDate.js b/lib/ChangeDueDateDialog/ChangeDueDate.js index 2930ead93..7d77a863a 100644 --- a/lib/ChangeDueDateDialog/ChangeDueDate.js +++ b/lib/ChangeDueDateDialog/ChangeDueDate.js @@ -2,9 +2,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { get, isEqual, pickBy } from 'lodash'; import { FormattedMessage } from 'react-intl'; -import moment from 'moment-timezone'; -import { Button, Icon, Layout } from '@folio/stripes-components'; +import { Button, Icon, Layout, dayjs } from '@folio/stripes-components'; import DueDatePicker from './DueDatePicker'; import LoanList from './LoanList'; @@ -27,8 +26,8 @@ class ChangeDueDate extends React.Component { } static newDueDateIsInThePast(props, state) { - const requestedDueDate = moment(state.datetime); - const currentDate = moment.tz('UTC'); + const requestedDueDate = dayjs(state.datetime); + const currentDate = dayjs.tz('UTC'); return requestedDueDate.isBefore(currentDate); } @@ -38,8 +37,8 @@ class ChangeDueDate extends React.Component { if (!user || !user.expirationDate) return false; - const requestedDueDate = moment(state.datetime); - const userExpirationDate = moment(user.expirationDate); + const requestedDueDate = dayjs(state.datetime); + const userExpirationDate = dayjs(user.expirationDate); return userExpirationDate.isBefore(requestedDueDate); } diff --git a/lib/ChangeDueDateDialog/DueDatePicker.js b/lib/ChangeDueDateDialog/DueDatePicker.js index 3568e28d6..2793332d6 100644 --- a/lib/ChangeDueDateDialog/DueDatePicker.js +++ b/lib/ChangeDueDateDialog/DueDatePicker.js @@ -1,8 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import moment from 'moment-timezone'; import { injectIntl } from 'react-intl'; - +import { dayjs } from '@folio/stripes-components'; import DueDatePickerForm from './DueDatePickerForm'; class DueDatePicker extends React.Component { @@ -43,7 +42,7 @@ class DueDatePicker extends React.Component { const date = values.date.split('T')[0]; const time = values.time.split(/[Z+-]/)[0]; - const localDatetime = moment.tz(`${date}T${time}`, timeZone); + const localDatetime = dayjs.tz(`${date}T${time}`, timeZone); const utcDatetime = localDatetime.tz('UTC').format(); this.props.onChange(utcDatetime); diff --git a/lib/ProxyManager/proxyUtil.js b/lib/ProxyManager/proxyUtil.js index 75bd7a1ec..fe822f513 100644 --- a/lib/ProxyManager/proxyUtil.js +++ b/lib/ProxyManager/proxyUtil.js @@ -1,15 +1,15 @@ import { get } from 'lodash'; -import moment from 'moment'; // eslint-disable-line import/no-extraneous-dependencies +import { dayjs } from '@folio/stripes-components'; export function isProxyExpired(user, proxyMap) { const proxy = proxyMap[user.id]; return proxy && proxy.expirationDate && - moment(proxy.expirationDate).isSameOrBefore(new Date()); + dayjs(proxy.expirationDate).isSameOrBefore(new Date()); } export function isSponsorExpired(sponsor) { return sponsor && sponsor.expirationDate && - moment(sponsor.expirationDate).isSameOrBefore(new Date()); + dayjs(sponsor.expirationDate).isSameOrBefore(new Date()); } export function isRequestForSponsorInvalid(user, proxyMap) { diff --git a/lib/SearchAndSort/components/DateRangeFilter/date-validations.js b/lib/SearchAndSort/components/DateRangeFilter/date-validations.js index 2694d83af..81fcc6eef 100644 --- a/lib/SearchAndSort/components/DateRangeFilter/date-validations.js +++ b/lib/SearchAndSort/components/DateRangeFilter/date-validations.js @@ -1,9 +1,9 @@ -import moment from 'moment'; +import { dayjs } from '@folio/stripes-components'; export const isDateValid = (date, dateFormat) => { - const momentDateWrapper = moment(date, dateFormat, true); + const dayjsDateWrapper = dayjs(date, dateFormat, true); - return momentDateWrapper.isValid(); + return dayjsDateWrapper.isValid(); }; export const validateDateRange = (dateRange, dateFormat) => { @@ -12,8 +12,8 @@ export const validateDateRange = (dateRange, dateFormat) => { endDate, } = dateRange; - const startDateMomentWrapper = moment(startDate, dateFormat, true); - const endDateMomentWrapper = moment(endDate, dateFormat, true); + const startDateDayJSWrapper = dayjs(startDate, dateFormat, true); + const endDateDayJSWrapper = dayjs(endDate, dateFormat, true); const startDateEmpty = startDate === ''; const endDateEmpty = endDate === ''; @@ -25,7 +25,7 @@ export const validateDateRange = (dateRange, dateFormat) => { const endDateInvalid = !endDateEmpty && !isDateValid(endDate, dateFormat); const bothDatesValid = !startDateInvalid && !endDateInvalid; - const wrongDatesOrder = bothDatesValid && startDateMomentWrapper.isAfter(endDateMomentWrapper); + const wrongDatesOrder = bothDatesValid && startDateDayJSWrapper.isAfter(endDateDayJSWrapper); const dateRangeValid = bothDatesEntered && bothDatesValid && !wrongDatesOrder; From dccb2abd32074cefe7c873c57f6b5db6f74714cb Mon Sep 17 00:00:00 2001 From: John Coburn Date: Fri, 5 Jan 2024 15:01:17 -0600 Subject: [PATCH 2/2] remove moment dependency --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 3f2dac0e8..1846d05d7 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "inflected": "^2.0.4", "miragejs": "^0.1.40", "mocha": "^10.2.0", - "moment": "^2.29.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-intl": "^6.4.4", @@ -83,7 +82,6 @@ "final-form": "^4.18.2", "final-form-arrays": "^3.0.2", "lodash": "^4.17.4", - "moment-timezone": "^0.5.17", "prop-types": "^15.5.10", "prop-types-extra": "^1.1.0", "query-string": "^7.1.2",