mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 07:32:19 -05:00
Set default date for new events to the next full hour
This commit is contained in:
parent
b4f8e4402e
commit
88e0649e79
|
|
@ -34,6 +34,7 @@ import {
|
|||
dateToDatabaseTimestamp,
|
||||
databaseTimestampToDate,
|
||||
getDateWithHoursOffset,
|
||||
getDateAtNextFullHour,
|
||||
} from "~/utils/dates";
|
||||
import {
|
||||
badRequestIfFalsy,
|
||||
|
|
@ -312,7 +313,9 @@ function DatesInput() {
|
|||
date: databaseTimestampToDate(t),
|
||||
}));
|
||||
}
|
||||
return [{ key: getKey(), date: new Date() }];
|
||||
|
||||
// Initial date rounded to next full hour from now
|
||||
return [{ key: getKey(), date: getDateAtNextFullHour(new Date()) }];
|
||||
});
|
||||
|
||||
const datesCount = datesInputState.length;
|
||||
|
|
@ -334,7 +337,7 @@ function DatesInput() {
|
|||
|
||||
const addedDate = lastValidDate
|
||||
? getDateWithHoursOffset(lastValidDate, NEW_CALENDAR_EVENT_HOURS_OFFSET)
|
||||
: new Date();
|
||||
: getDateAtNextFullHour(new Date());
|
||||
|
||||
return [...current, { key: getKey(), date: addedDate }];
|
||||
});
|
||||
|
|
|
|||
|
|
@ -79,3 +79,13 @@ export function getDateWithHoursOffset(date: Date, hoursOffset: number) {
|
|||
copiedDate.setHours(date.getHours() + hoursOffset);
|
||||
return copiedDate;
|
||||
}
|
||||
|
||||
export function getDateAtNextFullHour(date: Date) {
|
||||
const copiedDate = new Date(date.getTime());
|
||||
if (date.getMinutes() > 0) {
|
||||
copiedDate.setHours(date.getHours() + 1);
|
||||
copiedDate.setMinutes(0);
|
||||
}
|
||||
copiedDate.setSeconds(0);
|
||||
return copiedDate;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user