Skip to content

Commit 89c724c

Browse files
authored
Merge pull request #3 from pmaidens/tooFar
fix: you should not be able to go further than the last date
2 parents 52105bc + 233685c commit 89c724c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Utils/date.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,25 @@ export const getFormattedDate = (language: string, date: Date | number, options?
4545
month: "long",
4646
year: "numeric",
4747
}
48-
48+
4949
if (options) defaultOptions = options
5050

5151
return new Intl.DateTimeFormat(language, defaultOptions).format(date)
5252
}
5353

5454
export const goToPrevNext = (view: Views, date: Date, direction: number): number => {
55+
const newDate = new Date(date.toString())
5556
switch (view) {
5657
case "days":
57-
return addMonths(date, direction)
58+
return addMonths(newDate, direction)
5859
case "months":
59-
return addYears(date, direction)
60+
return addYears(newDate, direction)
6061
case "years":
61-
return addYears(date, direction * 10)
62+
return addYears(newDate, direction * 10)
6263
case "decades":
63-
return addYears(date, direction * 100)
64+
return addYears(newDate, direction * 100)
6465
default:
65-
return addYears(date, direction * 10)
66+
return addYears(newDate, direction * 10)
6667
}
6768
}
6869

0 commit comments

Comments
 (0)