Skip to content

Commit

Permalink
replace moment calls with dayjs
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnC-80 committed Jan 5, 2024
1 parent d3dc0f4 commit 1d3b534
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
11 changes: 5 additions & 6 deletions lib/ChangeDueDateDialog/ChangeDueDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/ChangeDueDateDialog/DueDatePicker.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/ProxyManager/proxyUtil.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions lib/SearchAndSort/components/DateRangeFilter/date-validations.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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 === '';
Expand All @@ -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;

Expand Down

0 comments on commit 1d3b534

Please sign in to comment.