Skip to content

Commit

Permalink
Tidy date using mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
vespasianvs committed Feb 21, 2025
1 parent c399ec9 commit 47196b8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { RRule } from "rrule";
import { ProcessedEvent } from "./lib/types";
import { convertDateToRRuleDate } from "./lib/helpers/generals";

const createDate = (startHour: number, startMinutes?: number, days?: number, months?: number) => {
let date = new Date(new Date().setHours(startHour)).setMinutes(0);
if (startMinutes) {
date = new Date(date).setMinutes(startMinutes);
}
if (days) {
date = new Date(date).setDate(new Date().getDate() + days);
}
if (months) {
date = new Date(date).setMonth(new Date().getMonth() + months);
}
const createDate = (
startHour: number,
startMinutes: number = 0,
days: number = 0,
months: number = 0
) => {
const date = new Date();
date.setHours(startHour);
date.setMinutes(startMinutes);
date.setDate(date.getDate() + days);
date.setMonth(date.getMonth() + months);

return new Date(date);
};

Expand Down

0 comments on commit 47196b8

Please sign in to comment.