Podpora víkendů

This commit is contained in:
Martin Berka 2023-06-02 21:12:38 +02:00
parent d59e439588
commit ec1cbf332b
5 changed files with 58 additions and 49 deletions

View File

@ -93,6 +93,7 @@ function App() {
<>
<Header />
<div className='wrapper'>
{data.isWeekend ? <h4>Užívejte víkend :)</h4> : <>
<Alert variant={'primary'}>
Tvé zobrazované jméno je {auth.login}. Změnu můžeš provést v local storage prohlížeče.<br />
<small>Pro gamer move: Změň si své jméno na cizí. Můžeš pak libovolně měnit jejich volbu.</small>
@ -138,6 +139,7 @@ function App() {
}
</div>
</div>
</>}
{/* {!pizzaDayExists &&
<div>
<p>Pro dnešní den není aktuálně založen Pizza day.</p>

View File

@ -19,6 +19,7 @@ export interface Choices {
export interface ClientData {
date: string, // dnešní datum pro zobrazení
isWeekend: boolean, // příznak zda je dnešní den víkend
choices: Choices, // seznam voleb
}

View File

@ -1,6 +1,6 @@
import { ClientData, Locations } from "./types";
import { db } from "./database";
import { getTodayString } from "./utils";
import { getHumanDate, getIsWeekend } from "./utils";
import { getDate } from "./utils";
// /** Jedna konkrétní pizza */
@ -33,7 +33,7 @@ import { getDate } from "./utils";
/** Vrátí "prázdná" (implicitní) data, pokud ještě nikdo nehlasoval. */
function getEmptyData(): ClientData {
return { date: getTodayString(), choices: {} };
return { date: getHumanDate(new Date()), isWeekend: getIsWeekend(new Date()), choices: {} };
}
/**

View File

@ -4,6 +4,7 @@ export interface Choices {
export interface ClientData {
date: string, // dnešní datum pro zobrazení
isWeekend: boolean, // příznak, zda je dnes víkend
choices: Choices, // seznam voleb
}

View File

@ -6,12 +6,17 @@ export function getDate() {
return `${currentYear}-${currentMonth}-${currentDay}`;
}
/** Vrátí human-readable reprezentaci dnešního data pro zobrazení. */
export function getTodayString() {
const date = new Date();
/** Vrátí human-readable reprezentaci předaného data pro zobrazení. */
export function getHumanDate(date: Date) {
let currentDay = String(date.getDate()).padStart(2, '0');
let currentMonth = String(date.getMonth() + 1).padStart(2, "0");
let currentYear = date.getFullYear();
let currentDayOfWeek = date.toLocaleDateString("CZ-cs", { weekday: 'long' });
return `${currentDay}.${currentMonth}.${currentYear} (${currentDayOfWeek})`;
}
/** 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'
}