Skip to content

Commit

Permalink
fix: lower date-fns dependency version
Browse files Browse the repository at this point in the history
- adjusted helper function to reflect version changes
- removed old un-used helper functions
  • Loading branch information
vicdotexe committed Jan 17, 2024
1 parent acc9436 commit 7b245f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
15 changes: 9 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"docs:serve": "vitepress serve docs"
},
"dependencies": {
"date-fns": "^3.0.0",
"date-fns": "^2.28.0 || ^3.0.0",
"vue": "^3.3.12"
},
"devDependencies": {
Expand Down
39 changes: 1 addition & 38 deletions src/helpers/DateHelper.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import { addDays, startOfWeek, isWeekend, Day } from "date-fns";

export function getWeekRange(
date: Date | string,
startDayOfWeek: number = 0
): { start: Date; end: Date } {
if (typeof date == typeof "string") {
date = new Date(date + "T00:00:00");
}
const startDate = new Date(date);
const endDate = new Date(date);
// Calculate the difference from the start day of the week
let dayDifference = startDate.getDay() - startDayOfWeek;

// Correct the day difference if the day is before the start day of the week
if (dayDifference < 0) {
dayDifference += 7;
}

// Adjust the start and end dates
startDate.setDate(startDate.getDate() - dayDifference);
endDate.setDate(startDate.getDate() + 6);

// Ensure start and end dates are at the beginning and end of their respective days
startDate.setHours(0, 0, 0, 0); // Set to start of the day
endDate.setHours(23, 59, 59, 999); // Set to end of the day

return { start: startDate, end: endDate };
}

export function getWeekDays(
date: Date | string,
date: Date,
includeWeekends: boolean = true,
startDayOfWeek: Day = 0
): Date[] {
Expand All @@ -47,12 +19,3 @@ export function getWeekDays(

return weekDays;
}

export function mergeTime(date: Date, time: Date) {
const newDate = new Date(date);
newDate.setHours(time.getHours());
newDate.setMinutes(time.getMinutes());
newDate.setSeconds(time.getSeconds());
newDate.setMilliseconds(time.getMilliseconds());
return newDate;
}

0 comments on commit 7b245f8

Please sign in to comment.