-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Upgrade date-fns to v3 #4481
Upgrade date-fns to v3 #4481
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,10 @@ import { | |
isDateBefore, | ||
getMidnightDate, | ||
} from "../src/date_utils"; | ||
import setMinutes from "date-fns/setMinutes"; | ||
import setHours from "date-fns/setHours"; | ||
import addQuarters from "date-fns/addQuarters"; | ||
import ptBR from "date-fns/locale/pt-BR"; | ||
import { setMinutes } from "date-fns/setMinutes"; | ||
import { setHours } from "date-fns/setHours"; | ||
import { addQuarters } from "date-fns/addQuarters"; | ||
import { ptBR } from "date-fns/locale/pt-BR"; | ||
import { registerLocale } from "../src/date_utils"; | ||
import { addYears } from "date-fns"; | ||
|
||
|
@@ -249,15 +249,15 @@ describe("date_utils", () => { | |
).toBe(true); | ||
}); | ||
|
||
it("should throw error if excluded date interval is invalid", () => { | ||
it("should be enabled and normalize negative intervals correctly", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const day = newDate(); | ||
expect(() => | ||
expect( | ||
isDayDisabled(day, { | ||
excludeDateIntervals: [ | ||
{ start: addDays(day, 1), end: subDays(day, 1) }, | ||
], | ||
}), | ||
).toThrow("Invalid interval"); | ||
).toBe(true); | ||
}); | ||
|
||
it("should be enabled if excluded date interval is empty", () => { | ||
|
@@ -366,15 +366,15 @@ describe("date_utils", () => { | |
).toBe(false); | ||
}); | ||
|
||
it("should throw error if excluded date interval is invalid", () => { | ||
it("should be enabled and normalize negative intervals correctly", () => { | ||
const day = newDate(); | ||
expect(() => | ||
expect( | ||
isDayExcluded(day, { | ||
excludeDateIntervals: [ | ||
{ start: addDays(day, 1), end: subDays(day, 1) }, | ||
], | ||
}), | ||
).toThrow("Invalid interval"); | ||
).toBe(true); | ||
}); | ||
|
||
it("should not be excluded if in excluded dates and not within excluded date intervals", () => { | ||
|
@@ -852,12 +852,12 @@ describe("date_utils", () => { | |
expect(isTimeInDisabledRange(time, { minTime, maxTime })).toBe(true); | ||
}); | ||
|
||
it("should not throw an exception if max time is before min time", () => { | ||
it("should correctly handle max time is before min time", () => { | ||
const date = newDate("2016-03-15"); | ||
const time = setHours(setMinutes(date, 30), 10); | ||
const minTime = setHours(setMinutes(date, 30), 5); | ||
const maxTime = setHours(setMinutes(date, 30), 0); | ||
expect(isTimeInDisabledRange(time, { minTime, maxTime })).toBe(false); | ||
expect(isTimeInDisabledRange(time, { minTime, maxTime })).toBe(true); | ||
}); | ||
}); | ||
|
||
|
@@ -890,11 +890,11 @@ describe("date_utils", () => { | |
expect(isDayInRange(day, startDate, endDate)).toBe(false); | ||
}); | ||
|
||
it("should not throw exception if end date is before start date", () => { | ||
it("should correctly handle max time is before min time", () => { | ||
const day = newDate("2016-02-01 09:40"); | ||
const startDate = newDate("2016-02-15 09:40"); | ||
const endDate = newDate("2016-01-15 08:40"); | ||
expect(isDayInRange(day, startDate, endDate)).toBe(false); | ||
expect(isDayInRange(day, startDate, endDate)).toBe(true); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the new changes, I believe you can also combine this:
🔹 Simplify Code (Nice to have)
James D