Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STSMACOM-724 Replace moment with dayjs #1425

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replace moment calls with dayjs
JohnC-80 committed Jan 5, 2024
commit 1d3b534902f7c72f8223a62235f2cb89b2ffa852
11 changes: 5 additions & 6 deletions lib/ChangeDueDateDialog/ChangeDueDate.js
Original file line number Diff line number Diff line change
@@ -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);
}
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 {
@@ -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);
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) {
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) => {
@@ -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;