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

chore(deps): bump date-fns to v3 #656

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Abstraction over common JavaScript date management libraries.
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

The project exposes an abstraction interface over [luxon](https://moment.github.io/luxon/), [date-fns v2](https://github.com/date-fns/date-fns), [dayjs](https://github.com/iamkun/dayjs) and [moment](https://momentjs.com/).
The project exposes an abstraction interface over [luxon](https://moment.github.io/luxon/), [date-fns v3](https://github.com/date-fns/date-fns), [dayjs](https://github.com/iamkun/dayjs) and [moment](https://momentjs.com/).
It allows you to build any UI date or time components while utilizing the same date management library in use within your user's project.

It simplifies timezone management, allows your code to return the exact same type that your user expects and works with specific calendar systems (e.g. [Jalali calendar](https://en.wikipedia.org/wiki/Jalali_calendar))
Expand Down
2 changes: 1 addition & 1 deletion __tests__/date-fns-jalali.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DateFnsJalaliUtils from "../packages/date-fns-jalali/src";
import { TEST_TIMESTAMP } from "./test-utils";
import ruLocale from "date-fns/locale/ru";
import { ru as ruLocale } from "date-fns/locale/ru";

const date = new Date(TEST_TIMESTAMP); /* 1397/08/08 سه‌شنبه*/
const dateTimeFormat = "yyyy/MM/dd HH:mm";
Expand Down
4 changes: 2 additions & 2 deletions __tests__/formats.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ruDateFnsLocale from "date-fns/locale/ru";
import { ru as ruDateFnsLocale } from "date-fns/locale/ru";
import LuxonUtils from "../packages/luxon/src";
import DateFnsUtils from "../packages/date-fns/src";
import MomentUtils from "../packages/moment/src";
Expand Down Expand Up @@ -85,7 +85,7 @@ describe("Localized formats", () => {
test.each`
format | expectedWithEn | expectedWithRu
${"fullDate"} | ${"Feb 1, 2020"} | ${"1 фев. 2020 г."}
${"fullDateWithWeekday"} | ${"Saturday, February 1st, 2020"} | ${"суббота, 1 февраля 2020 г."}
${"fullDateWithWeekday"} | ${"Saturday, February 1st, 2020"} | ${"суббота, 1 февраля 2020 г."}
${"fullDateTime"} | ${"Feb 1, 2020 11:44 PM"} | ${"1 фев. 2020 г. 23:44"}
frsimond marked this conversation as resolved.
Show resolved Hide resolved
${"fullDateTime12h"} | ${"Feb 1, 2020 11:44 PM"} | ${"1 фев. 2020 г. 11:44 ПП"}
${"fullDateTime24h"} | ${"Feb 1, 2020 23:44"} | ${"1 фев. 2020 г. 23:44"}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/localization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import advancedDayJsFormat from "dayjs/plugin/advancedFormat";
import LuxonUtils from "../packages/luxon/src";
import { TEST_TIMESTAMP, utilsTest } from "./test-utils";
import DayjsUtils from "../packages/dayjs/src";
import ruLocale from "date-fns/locale/ru";
import enAuLocale from "date-fns/locale/en-AU";
import { ru as ruLocale } from "date-fns/locale/ru";
import { enAU as enAuLocale } from "date-fns/locale/en-AU";
import DateFnsUtils from "../packages/date-fns/src";
import MomentUtils from "../packages/moment/src";
import JsJodaUtils from "../packages/js-joda/src";
Expand Down
4 changes: 2 additions & 2 deletions packages/date-fns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"license": "MIT",
"peerDependencies": {
"date-fns": "^2.0.0"
"date-fns": "^3.2.0"
},
"peerDependenciesMeta": {
"date-fns": {
Expand All @@ -41,7 +41,7 @@
"@date-io/core": "^2.17.0"
},
"devDependencies": {
"date-fns": "2.16.1",
"date-fns": "^3.2.0",
"rollup": "^2.0.2",
"typescript": "^5.0.0"
},
Expand Down
120 changes: 59 additions & 61 deletions packages/date-fns/src/date-fns-utils.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,57 @@
import addDays from "date-fns/addDays";
import addSeconds from "date-fns/addSeconds";
import addMinutes from "date-fns/addMinutes";
import addHours from "date-fns/addHours";
import addWeeks from "date-fns/addWeeks";
import addMonths from "date-fns/addMonths";
import addYears from "date-fns/addYears";
import differenceInYears from "date-fns/differenceInYears";
import differenceInQuarters from "date-fns/differenceInQuarters";
import differenceInMonths from "date-fns/differenceInMonths";
import differenceInWeeks from "date-fns/differenceInWeeks";
import differenceInDays from "date-fns/differenceInDays";
import differenceInHours from "date-fns/differenceInHours";
import differenceInMinutes from "date-fns/differenceInMinutes";
import differenceInSeconds from "date-fns/differenceInSeconds";
import differenceInMilliseconds from "date-fns/differenceInMilliseconds";
import eachDayOfInterval from "date-fns/eachDayOfInterval";
import endOfDay from "date-fns/endOfDay";
import endOfWeek from "date-fns/endOfWeek";
import endOfYear from "date-fns/endOfYear";
import format from "date-fns/format";
import getDate from "date-fns/getDate";
import getDay from "date-fns/getDay";
import getDaysInMonth from "date-fns/getDaysInMonth";
import getHours from "date-fns/getHours";
import getMinutes from "date-fns/getMinutes";
import getMonth from "date-fns/getMonth";
import getSeconds from "date-fns/getSeconds";
import getYear from "date-fns/getYear";
import isAfter from "date-fns/isAfter";
import isBefore from "date-fns/isBefore";
import isEqual from "date-fns/isEqual";
import isSameDay from "date-fns/isSameDay";
import isSameYear from "date-fns/isSameYear";
import isSameMonth from "date-fns/isSameMonth";
import isSameHour from "date-fns/isSameHour";
import isValid from "date-fns/isValid";
import dateFnsParse from "date-fns/parse";
import setDate from "date-fns/setDate";
import setHours from "date-fns/setHours";
import setMinutes from "date-fns/setMinutes";
import setMonth from "date-fns/setMonth";
import setSeconds from "date-fns/setSeconds";
import setYear from "date-fns/setYear";
import startOfDay from "date-fns/startOfDay";
import startOfMonth from "date-fns/startOfMonth";
import endOfMonth from "date-fns/endOfMonth";
import startOfWeek from "date-fns/startOfWeek";
import startOfYear from "date-fns/startOfYear";
import parseISO from "date-fns/parseISO";
import formatISO from "date-fns/formatISO";
import { addDays } from "date-fns/addDays";
import { addSeconds } from "date-fns/addSeconds";
import { addMinutes } from "date-fns/addMinutes";
import { addHours } from "date-fns/addHours";
import { addWeeks } from "date-fns/addWeeks";
import { addMonths } from "date-fns/addMonths";
import { addYears } from "date-fns/addYears";
import { differenceInYears } from "date-fns/differenceInYears";
import { differenceInQuarters } from "date-fns/differenceInQuarters";
import { differenceInMonths } from "date-fns/differenceInMonths";
import { differenceInWeeks } from "date-fns/differenceInWeeks";
import { differenceInDays } from "date-fns/differenceInDays";
import { differenceInHours } from "date-fns/differenceInHours";
import { differenceInMinutes } from "date-fns/differenceInMinutes";
import { differenceInSeconds } from "date-fns/differenceInSeconds";
import { differenceInMilliseconds } from "date-fns/differenceInMilliseconds";
import { eachDayOfInterval } from "date-fns/eachDayOfInterval";
import { endOfDay } from "date-fns/endOfDay";
import { endOfWeek } from "date-fns/endOfWeek";
import { endOfYear } from "date-fns/endOfYear";
import { format, longFormatters } from "date-fns/format";
import { getDate } from "date-fns/getDate";
import { getDay } from "date-fns/getDay";
import { getDaysInMonth } from "date-fns/getDaysInMonth";
import { getHours } from "date-fns/getHours";
import { getMinutes } from "date-fns/getMinutes";
import { getMonth } from "date-fns/getMonth";
import { getSeconds } from "date-fns/getSeconds";
import { getYear } from "date-fns/getYear";
import { isAfter } from "date-fns/isAfter";
import { isBefore } from "date-fns/isBefore";
import { isEqual } from "date-fns/isEqual";
import { isSameDay } from "date-fns/isSameDay";
import { isSameYear } from "date-fns/isSameYear";
import { isSameMonth } from "date-fns/isSameMonth";
import { isSameHour } from "date-fns/isSameHour";
import { isValid } from "date-fns/isValid";
import { parse as dateFnsParse } from "date-fns/parse";
import { setDate } from "date-fns/setDate";
import { setHours } from "date-fns/setHours";
import { setMinutes } from "date-fns/setMinutes";
import { setMonth } from "date-fns/setMonth";
import { setSeconds } from "date-fns/setSeconds";
import { setYear } from "date-fns/setYear";
import { startOfDay } from "date-fns/startOfDay";
import { startOfMonth } from "date-fns/startOfMonth";
import { endOfMonth } from "date-fns/endOfMonth";
import { startOfWeek } from "date-fns/startOfWeek";
import { startOfYear } from "date-fns/startOfYear";
import { parseISO } from "date-fns/parseISO";
import { formatISO } from "date-fns/formatISO";
import { IUtils, DateIOFormats, Unit } from "@date-io/core/IUtils";
import isWithinInterval from "date-fns/isWithinInterval";
// @ts-ignore
import longFormatters from "date-fns/_lib/format/longFormatters";
import defaultLocale from "date-fns/locale/en-US";
import { isWithinInterval } from "date-fns/isWithinInterval";
import { enUS as defaultLocale } from "date-fns/locale/en-US";

type Locale = typeof defaultLocale;

Expand All @@ -62,16 +60,16 @@ const defaultFormats: DateIOFormats = {
fullDate: "PP",
fullDateWithWeekday: "PPPP",
fullDateTime: "PP p",
fullDateTime12h: "PP hh:mm aaa",
fullDateTime12h: "PP hh:mm aa",
fullDateTime24h: "PP HH:mm",
fullTime: "p",
fullTime12h: "hh:mm aaa",
fullTime12h: "hh:mm aa",
fullTime24h: "HH:mm",
hours12h: "hh",
hours24h: "HH",
keyboardDate: "P",
keyboardDateTime: "P p",
keyboardDateTime12h: "P hh:mm aaa",
keyboardDateTime12h: "P hh:mm aa",
keyboardDateTime24h: "P HH:mm",
minutes: "mm",
month: "LLLL",
Expand Down Expand Up @@ -104,7 +102,7 @@ export default class DateFnsUtils implements IUtils<Date> {
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
public is12HourCycleInCurrentLocale = () => {
if (this.locale) {
return /a/.test(this.locale.formatLong?.time());
return /a/.test(this.locale.formatLong?.time({}));
}

// By default date-fns is using en-US locale with am/pm enabled
Expand All @@ -123,7 +121,7 @@ export default class DateFnsUtils implements IUtils<Date> {
const firstCharacter = token[0];
if (firstCharacter === "p" || firstCharacter === "P") {
const longFormatter = longFormatters[firstCharacter];
return longFormatter(token, locale.formatLong, {});
return longFormatter(token, locale.formatLong);
}
return token;
})
Expand Down Expand Up @@ -436,7 +434,7 @@ export default class DateFnsUtils implements IUtils<Date> {
let count = 0;
let current = start;
const nestedWeeks: Date[][] = [];
let lastDay = null;
let lastDay = null as null | number;
while (isBefore(current, end)) {
const weekNumber = Math.floor(count / 7);
nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
Expand Down
Loading