DayJS Replacement
This commit is contained in:
10
package-lock.json
generated
10
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 (
|
||||
<Typography.Title level={2}>
|
||||
{`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)}`}
|
||||
</Typography.Title>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="Loss Date">
|
||||
{job.loss_date ? moment(job.loss_date).format(DateFormat) : "No Loss Date"}
|
||||
{job.loss_date ? dayjs(job.loss_date).format(DateFormat) : "No Loss Date"}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</PageHeader>
|
||||
|
||||
@@ -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 }) {
|
||||
<DatePicker.RangePicker
|
||||
format="MM/DD/YYYY"
|
||||
ranges={{
|
||||
Today: [moment(), moment()],
|
||||
"Last 14 days": [moment().subtract(14, "days"), moment()],
|
||||
"Last 7 days": [moment().subtract(7, "days"), moment()],
|
||||
"Next 7 days": [moment(), moment().add(7, "days")],
|
||||
"Next 14 days": [moment(), moment().add(14, "days")],
|
||||
Today: [dayjs(), dayjs()],
|
||||
"Last 14 days": [dayjs().subtract(14, "day"), dayjs()],
|
||||
"Last 7 days": [dayjs().subtract(7, "day"), dayjs()],
|
||||
"Next 7 days": [dayjs(), dayjs().add(7, "day")],
|
||||
"Next 14 days": [dayjs(), dayjs().add(14, "day")],
|
||||
"Last Month": [
|
||||
moment().startOf("month").subtract(1, "month"),
|
||||
moment().startOf("month").subtract(1, "month").endOf("month"),
|
||||
dayjs().startOf("month").subtract(1, "month"),
|
||||
dayjs().startOf("month").subtract(1, "month").endOf("month"),
|
||||
],
|
||||
|
||||
"This Month": [
|
||||
moment().startOf("month"),
|
||||
moment().endOf("month"),
|
||||
dayjs().startOf("month"),
|
||||
dayjs().endOf("month"),
|
||||
],
|
||||
"Next Month": [
|
||||
moment().startOf("month").add(1, "month"),
|
||||
moment().startOf("month").add(1, "month").endOf("month"),
|
||||
dayjs().startOf("month").add(1, "month"),
|
||||
dayjs().startOf("month").add(1, "month").endOf("month"),
|
||||
],
|
||||
"Last Quarter": [
|
||||
moment().startOf("quarter").subtract(1, "quarters"),
|
||||
moment().startOf("quarter").subtract(1, "day"),
|
||||
dayjs().startOf("quarter").subtract(1, "quarter"),
|
||||
dayjs().startOf("quarter").subtract(1, "day"),
|
||||
],
|
||||
"This Quarter": [
|
||||
moment().startOf("quarter"),
|
||||
moment()
|
||||
dayjs().startOf("quarter"),
|
||||
dayjs()
|
||||
.startOf("quarter")
|
||||
.add(1, "quarter")
|
||||
.subtract(1, "day"),
|
||||
],
|
||||
"Last 3 Months": [
|
||||
moment().startOf("month").subtract(3, "month"),
|
||||
moment().startOf("month").subtract(1, "month").endOf("month"),
|
||||
dayjs().startOf("month").subtract(3, "month"),
|
||||
dayjs().startOf("month").subtract(1, "month").endOf("month"),
|
||||
],
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
exports.default = {
|
||||
webcontent: "webcontent-send",
|
||||
quit: "quit-app",
|
||||
test: {
|
||||
|
||||
@@ -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"),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
67
src/util/day.js
Normal file
67
src/util/day.js
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user