-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add avatar update based on holiday
- Loading branch information
1 parent
42df8ce
commit 47bcbb0
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function isDateInRange(startDate: string, endDate: string): boolean { | ||
const currentDate = new Date(); | ||
const startParts = startDate.split('/'); | ||
const endParts = endDate.split('/'); | ||
|
||
if (startParts.length !== 2 || endParts.length !== 2) { | ||
throw new Error('Invalid date format. Please use "dd/mm" format.'); | ||
} | ||
|
||
const startDay = parseInt(startParts[0], 10); | ||
const startMonth = parseInt(startParts[1], 10) - 1; | ||
const endDay = parseInt(endParts[0], 10); | ||
const endMonth = parseInt(endParts[1], 10) - 1; | ||
|
||
const endDateIsNextYear = endMonth < startMonth; | ||
|
||
const startDateObj = new Date( | ||
currentDate.getFullYear(), | ||
startMonth, | ||
startDay | ||
); | ||
const endDateObj = new Date( | ||
currentDate.getFullYear() + (endDateIsNextYear ? 1 : 0), | ||
endMonth, | ||
endDay | ||
); | ||
return currentDate >= startDateObj && currentDate <= endDateObj; | ||
} |