Zobrazování data u poslední aktualizace menu

This commit is contained in:
2023-11-10 20:22:47 +01:00
parent 3021e6159d
commit 2b9d817af5
4 changed files with 19 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish,
import Loader from './components/Loader';
import { getData, errorHandler, getQrUrl } from './api/Api';
import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed } from './api/FoodApi';
import { getHumanDateTime } from './Utils';
const EVENT_CONNECT = "connect"
@@ -315,7 +316,7 @@ function App() {
}
return <Col md={12} lg={4}>
<h3>{name}</h3>
{menu?.lastUpdate && <small>Poslední aktualizace: {menu.lastUpdate}</small>}
{menu?.lastUpdate && <small>Poslední aktualizace: {getHumanDateTime(new Date(menu.lastUpdate))}</small>}
{content}
</Col>
}

View File

@@ -35,4 +35,16 @@ export const getToken = (): string | null => {
*/
export const deleteToken = () => {
localStorage.removeItem(TOKEN_KEY);
}
}
/**
* Vrátí human-readable reprezentaci předaného data a času pro zobrazení.
*/
export function getHumanDateTime(datetime: Date) {
let currentDay = String(datetime.getDate()).padStart(2, '0');
let currentMonth = String(datetime.getMonth() + 1).padStart(2, "0");
let currentYear = datetime.getFullYear();
let currentHours = String(datetime.getHours()).padStart(2, '0');
let currentMinutes = String(datetime.getMinutes()).padStart(2, "0");
return `${currentDay}.${currentMonth}.${currentYear} ${currentHours}:${currentMinutes}`;
}