Možnost náhledu a výběru na další dny v týdnu

This commit is contained in:
2023-09-06 19:22:19 +02:00
parent 5379c21203
commit 832d3089ec
9 changed files with 766 additions and 304 deletions

View File

@@ -22,8 +22,19 @@ export function getHumanTime(time: Date) {
return `${currentHours}:${currentMinutes}`;
}
/**
* Vrátí index dne v týdnu, kde pondělí=0, neděle=6
*
* @param date datum
* @returns index dne v týdnu
*/
export const getDayOfWeekIndex = (date: Date) => {
// https://stackoverflow.com/a/4467559
return (((date.getDay() - 1) % 7) + 7) % 7;
}
/** Vrátí true, pokud je předané datum o víkendu. */
export function getIsWeekend(date: Date) {
const dayName = date.toLocaleDateString("CZ-cs", { weekday: 'long' }).toLowerCase()
return dayName === 'sobota' || dayName === 'neděle'
const index = getDayOfWeekIndex(date);
return index == 5 || index == 6;
}