diff --git a/package-lock.json b/package-lock.json index 0169e64..40f05bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "apollo-link-logger": "^2.0.1", "apollo-link-sentry": "^3.3.0", "chokidar": "^3.6.0", + "dayjs": "^1.11.10", + "dayjs-business-days2": "^1.2.2", "dbffile": "^1.9.3", "dinero.js": "^1.9.1", "electron-context-menu": "^3.6.1", @@ -6579,6 +6581,14 @@ "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" }, + "node_modules/dayjs-business-days2": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/dayjs-business-days2/-/dayjs-business-days2-1.2.2.tgz", + "integrity": "sha512-tYwNKeMxuNEpGw2k5j/KTcH0c1lV+41wfqkTN21OvP2hwZFnpM4dH2biaOI2gElRmJOQQxkKByuH5bZPlea/Jg==", + "dependencies": { + "dayjs": "^1.11.10" + } + }, "node_modules/dbffile": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/dbffile/-/dbffile-1.9.3.tgz", diff --git a/package.json b/package.json index 1c45ffe..1791c2d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "apollo-link-logger": "^2.0.1", "apollo-link-sentry": "^3.3.0", "chokidar": "^3.6.0", + "dayjs": "^1.11.10", + "dayjs-business-days2": "^1.2.2", "dbffile": "^1.9.3", "dinero.js": "^1.9.1", "electron-context-menu": "^3.6.1", diff --git a/src/components/atoms/reporting-title/reporting-title.atom.jsx b/src/components/atoms/reporting-title/reporting-title.atom.jsx index 7f9cfce..1d59338 100644 --- a/src/components/atoms/reporting-title/reporting-title.atom.jsx +++ b/src/components/atoms/reporting-title/reporting-title.atom.jsx @@ -4,7 +4,8 @@ import React from "react"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { selectDates } from "../../../redux/reporting/reporting.selectors"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; + import { DateFormat } from "../../../util/constants"; const mapStateToProps = createStructuredSelector({ dates: selectDates, @@ -13,9 +14,9 @@ const mapStateToProps = createStructuredSelector({ export function ReportingTitleAtom({ dates }) { return ( - {`RPS Report for Period from ${moment(dates.startDate).format( + {`RPS Report for Period from ${dayjs(dates.startDate).format( DateFormat - )} to ${moment(dates.endDate).format(DateFormat)}`} + )} to ${dayjs(dates.endDate).format(DateFormat)}`} ); } diff --git a/src/components/atoms/time-ago-formatter/time-ago-formatter.atom.jsx b/src/components/atoms/time-ago-formatter/time-ago-formatter.atom.jsx index dd40e4d..996de31 100644 --- a/src/components/atoms/time-ago-formatter/time-ago-formatter.atom.jsx +++ b/src/components/atoms/time-ago-formatter/time-ago-formatter.atom.jsx @@ -1,10 +1,11 @@ import { Tooltip } from "antd"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; + import React, { useEffect, useState } from "react"; export default function TimeAgoFormatter(props) { const [timestampString, setTimestampString] = useState(""); - const m = moment(props.children); + const m = dayjs(props.children); useEffect(() => { const timer = setInterval(() => setTimestampString(m.fromNow()), 15000); setTimestampString(m.fromNow()); diff --git a/src/components/molecules/close-date-display/close-date-display.molecule.jsx b/src/components/molecules/close-date-display/close-date-display.molecule.jsx index 6bbbba6..fa0e67c 100644 --- a/src/components/molecules/close-date-display/close-date-display.molecule.jsx +++ b/src/components/molecules/close-date-display/close-date-display.molecule.jsx @@ -1,7 +1,7 @@ import { WarningOutlined } from "@ant-design/icons"; import { useMutation } from "@apollo/client"; import { DatePicker, message, notification, Spin } from "antd"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; import React, { useState } from "react"; import { UPDATE_JOB } from "../../../graphql/jobs.queries"; import ipcTypes from "../../../ipc.types"; @@ -10,7 +10,7 @@ import { ChangeOfRuleSet, DateFormat } from "../../../util/constants"; const { ipcRenderer } = window; export default function CloseDateDisplayMolecule({ job, jobId, close_date }) { - const [value, setValue] = useState(moment(close_date)); + const [value, setValue] = useState(dayjs(close_date)); const [loading, setLoading] = useState(false); const [updateJob] = useMutation(UPDATE_JOB); @@ -21,8 +21,8 @@ export default function CloseDateDisplayMolecule({ job, jobId, close_date }) { setLoading(true); setValue(newDate); const requires_reimport = ChangeOfRuleSet({ - prevDateMoment: job.close_date ? moment(job.close_date) : moment(), - newDateMoment: newDate ? newDate : moment(), + prevDateMoment: job.close_date ? dayjs(job.close_date) : dayjs(), + newDateMoment: newDate ? newDate : dayjs(), }); if (requires_reimport) { notification.open({ diff --git a/src/components/molecules/jobs-detail-description/jobs-detail-description.molecule.jsx b/src/components/molecules/jobs-detail-description/jobs-detail-description.molecule.jsx index 02a26e8..a47efd1 100644 --- a/src/components/molecules/jobs-detail-description/jobs-detail-description.molecule.jsx +++ b/src/components/molecules/jobs-detail-description/jobs-detail-description.molecule.jsx @@ -8,7 +8,7 @@ import JobGroupMolecule from "../job-group/job-group.molecule"; import DeleteJobAtom from "../../atoms/delete-job/delete-job.atom"; import VehicleGroupAlertAtom from "../../atoms/vehicle-group-alert/vehicle-group-alert.atom"; import { DateFormat } from "../../../util/constants"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; import { PageHeader } from "@ant-design/pro-layout"; export default function JobsDetailDescriptionMolecule({ loading, job }) { @@ -69,7 +69,7 @@ export default function JobsDetailDescriptionMolecule({ loading, job }) { {job && job.joblines.filter((i) => !i.ignore && i.db_ref !== "900511").length} - {job.loss_date ? moment(job.loss_date).format(DateFormat) : "No Loss Date"} + {job.loss_date ? dayjs(job.loss_date).format(DateFormat) : "No Loss Date"} diff --git a/src/components/molecules/reporting-dates/reporting-dates.molecule.jsx b/src/components/molecules/reporting-dates/reporting-dates.molecule.jsx index 1b77cb1..f9ed46a 100644 --- a/src/components/molecules/reporting-dates/reporting-dates.molecule.jsx +++ b/src/components/molecules/reporting-dates/reporting-dates.molecule.jsx @@ -3,7 +3,7 @@ import React from "react"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { queryReportingData } from "../../../redux/reporting/reporting.actions"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; const mapStateToProps = createStructuredSelector({ //currentUser: selectCurrentUser }); @@ -40,7 +40,7 @@ export function ReportingDatesMolecule({ queryReportingData }) { } if ( - moment(value[1]).diff(moment(value[0]), "years", true) > 1 + dayjs(value[1]).diff(dayjs(value[0]), "years", true) > 1 ) { return Promise.reject( "Time period exceeds 1 year. Please select a shorter date range." @@ -55,38 +55,38 @@ export function ReportingDatesMolecule({ queryReportingData }) { diff --git a/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx b/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx index 4c40bc3..dac47a2 100644 --- a/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx +++ b/src/components/molecules/reporting-jobs-list/reporting-jobs-list.molecule.jsx @@ -1,6 +1,6 @@ import { CloudUploadOutlined } from "@ant-design/icons"; import { Alert, Input, Space, Table } from "antd"; -import moment from "moment"; +import dayjs from '../../../util/day.js'; import React, { useState } from "react"; import { useMemo } from "react"; import { connect } from "react-redux"; @@ -60,10 +60,10 @@ export function ReportingJobsListMolecule({ title: "R4P", dataIndex: "close_date", key: "close_date", - render: (text, record) => moment(record.close_date).format("MM/DD/yyyy"), + render: (text, record) => dayjs(record.close_date).format("MM/DD/yyyy"), defaultSortOrder: "ascend", sorter: (a, b) => - moment(a.close_date).unix() - moment(b.close_date).unix(), + dayjs(a.close_date).unix() - dayjs(b.close_date).unix(), }, { title: "Ins Co.", diff --git a/src/ipc.types.js b/src/ipc.types.js index 27acfcf..a220f2f 100644 --- a/src/ipc.types.js +++ b/src/ipc.types.js @@ -1,4 +1,4 @@ -export default { +exports.default = { webcontent: "webcontent-send", quit: "quit-app", test: { diff --git a/src/ipc/ipc-estimate-utils.js b/src/ipc/ipc-estimate-utils.js index e5468a8..dc26ff8 100644 --- a/src/ipc/ipc-estimate-utils.js +++ b/src/ipc/ipc-estimate-utils.js @@ -1,7 +1,6 @@ import { message } from "antd"; import gql from "graphql-tag"; import _ from "lodash"; -import moment from "moment"; import client from "../graphql/GraphQLClient"; import { INSERT_NEW_JOB, @@ -23,12 +22,12 @@ export function CalculateVehicleAge(job) { //Per new rules in 2023, we need to determine which set of rules to apply. const parsedYr = parseInt(job.v_model_yr); const vehicleYr = - moment().year() + 1 - 2000 >= parsedYr ? 2000 + parsedYr : 1900 + parsedYr; - const closeDate = moment(job.close_date); - const lossDate = moment(job.loss_date); + dayjs().year() + 1 - 2000 >= parsedYr ? 2000 + parsedYr : 1900 + parsedYr; + const closeDate = dayjs(job.close_date); + const lossDate = dayjs(job.loss_date); let ret; - if (closeDate.isSameOrAfter(moment("2023-04-01"))) { + if (closeDate.isSameOrAfter(dayjs("2023-04-01"))) { //Post April 2023 rules where the age is calculated based on loss date. ipcRenderer.send( ipcTypes.app.toMain.log.debug, @@ -43,7 +42,7 @@ export function CalculateVehicleAge(job) { "Using pre 0423 ruleset to calculate vehicle age for job.", job ); - ret = Math.max(0, moment(job.close_date || new Date()).year() - vehicleYr); + ret = Math.max(0, dayjs(job.close_date || new Date()).year() - vehicleYr); } return ret; @@ -231,7 +230,7 @@ const DetermineVehicleGroup = async (job) => { variables: { make: job.v_makedesc.toUpperCase(), type: job.v_type, - date: moment().format("YYYY-MM-DD"), + date: dayjs().format("YYYY-MM-DD"), }, }); diff --git a/src/redux/user/user.sagas.js b/src/redux/user/user.sagas.js index eafea3b..3f84542 100644 --- a/src/redux/user/user.sagas.js +++ b/src/redux/user/user.sagas.js @@ -1,5 +1,5 @@ import { message } from "antd"; -import moment from "moment"; +import dayjs from '../../util/day.js'; //import LogRocket from "logrocket"; import * as Sentry from "@sentry/electron"; import { all, call, delay, put, takeLatest } from "redux-saga/effects"; @@ -198,7 +198,7 @@ export function* checkForNotificationSaga() { data: { notifications }, } = yield client.query({ query: QUERY_NOTIFICATIONS, - variables: { now: moment() }, + variables: { now: dayjs() }, }); if (notifications) { diff --git a/src/util/constants.js b/src/util/constants.js index db79c7d..5dfa6ad 100644 --- a/src/util/constants.js +++ b/src/util/constants.js @@ -1,20 +1,20 @@ -import moment from "moment"; +import dayjs from './day.js' export const DateFormat = "MM/DD/yyyy"; const RuleSets = [ { title: "V1", - range: [moment("2010-01-01"), moment("2023-04-01")], + range: [dayjs("2010-01-01"), dayjs("2023-04-01")], }, { title: "V2", - range: [moment("2023-04-01"), moment("2040-01-01")], + range: [dayjs("2023-04-01"), dayjs("2040-01-01")], }, ]; - +//TODO: Verify that this doesnt need to be reversed. export function ChangeOfRuleSet({ - prevDateMoment = moment(), - newDateMoment = moment(), + prevDateMoment = dayjs(), + newDateMoment = dayjs(), }) { const prevRuleSet = RuleSets.find( (r) => @@ -32,11 +32,7 @@ export function ChangeOfRuleSet({ } export function WhichRulesetToApply(close_date) { - const DateMoment = close_date ? moment(close_date) : moment(); - console.log( - "🚀 ~ file: constants.js:36 ~ WhichRulesetToApply ~ DateMoment", - DateMoment - ); + const DateMoment = close_date ? dayjs(close_date) : dayjs(); const newRuleSet = RuleSets.find( (r) => DateMoment.isSameOrAfter(r.range[0]) && DateMoment.isBefore(r.range[1]) @@ -44,4 +40,4 @@ export function WhichRulesetToApply(close_date) { console.log("Using ruleset:", newRuleSet); return newRuleSet?.title; -} +} \ No newline at end of file diff --git a/src/util/day.js b/src/util/day.js new file mode 100644 index 0000000..3fb824b --- /dev/null +++ b/src/util/day.js @@ -0,0 +1,67 @@ +import dayjs from "dayjs"; + +import dayjsBusinessDays from "dayjs-business-days2"; +import isSameOrAfter from "dayjs/plugin/isSameOrAfter"; +import updateLocale from "dayjs/plugin/updateLocale"; +import isSameOrBefore from "dayjs/plugin/isSameOrBefore"; +import timezone from "dayjs/plugin/timezone"; +import utc from "dayjs/plugin/utc"; +import minMax from "dayjs/plugin/minMax"; +import isBetween from "dayjs/plugin/isBetween"; +import customParseFormat from "dayjs/plugin/customParseFormat"; +import pluralGetSet from "dayjs/plugin/pluralGetSet"; +import duration from "dayjs/plugin/duration"; +import advancedFormat from "dayjs/plugin/advancedFormat"; +import arraySupport from "dayjs/plugin/arraySupport"; +import calendar from "dayjs/plugin/calendar"; +import dayOfYear from "dayjs/plugin/dayOfYear"; +import weekday from "dayjs/plugin/weekday"; +import weekOfYear from "dayjs/plugin/weekOfYear"; +import weekYear from "dayjs/plugin/weekYear"; +import isoWeek from "dayjs/plugin/isoWeek"; +import isoWeeksInYear from "dayjs/plugin/isoWeeksInYear"; +import isLeapYear from "dayjs/plugin/isLeapYear"; +import localeData from "dayjs/plugin/localeData"; +import localizedFormat from "dayjs/plugin/localizedFormat"; +import quarterOfYear from "dayjs/plugin/quarterOfYear"; +import relativeTime from "dayjs/plugin/relativeTime"; +import isToday from "dayjs/plugin/isToday"; +import isTomorrow from "dayjs/plugin/isTomorrow"; +import isYesterday from "dayjs/plugin/isYesterday"; +import objectSupport from "dayjs/plugin/objectSupport"; +import toArray from "dayjs/plugin/toArray"; +import toObject from "dayjs/plugin/toObject"; + +dayjs.extend(toObject); +dayjs.extend(toArray); +dayjs.extend(objectSupport); +dayjs.extend(isYesterday); +dayjs.extend(isTomorrow); +dayjs.extend(isToday); +dayjs.extend(localeData); +dayjs.extend(quarterOfYear); +dayjs.extend(localizedFormat); +dayjs.extend(isLeapYear); +dayjs.extend(isoWeeksInYear); +dayjs.extend(isoWeek); +dayjs.extend(weekYear); +dayjs.extend(weekOfYear); +dayjs.extend(weekday); +dayjs.extend(dayOfYear); +dayjs.extend(calendar); +dayjs.extend(arraySupport); +dayjs.extend(advancedFormat); +dayjs.extend(duration); +dayjs.extend(relativeTime); +dayjs.extend(pluralGetSet); +dayjs.extend(customParseFormat); +dayjs.extend(utc); +dayjs.extend(timezone); +dayjs.extend(updateLocale); +dayjs.extend(isSameOrAfter); +dayjs.extend(isSameOrBefore); +dayjs.extend(minMax); +dayjs.extend(isBetween); +dayjs.extend(dayjsBusinessDays); + +export default dayjs;