DayJS Replacement
This commit is contained in:
@@ -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