2022-10-22 16:14:21 +02:00
|
|
|
/**
|
|
|
|
* Formats a Date to HH:MM, e.g. 09:23 or 13:37
|
|
|
|
*
|
|
|
|
* @param {Date} date
|
|
|
|
* @returns {string|undefined} Formatted time or undefined for non-Date
|
|
|
|
*/
|
|
|
|
export const formatTime = (date) => {
|
2022-11-26 14:50:59 +01:00
|
|
|
if (!date instanceof Date) return;
|
2022-12-04 12:00:18 +01:00
|
|
|
const hours = String(date.getHours()).padStart(2, '0');
|
|
|
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
|
|
|
|
|
|
return `${hours}:${minutes}`;
|
2022-12-22 18:28:51 +01:00
|
|
|
};
|
2022-10-22 16:14:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a Date to YYYY-MM-DD, e.g. 2023-05-18
|
|
|
|
*
|
|
|
|
* @param {Date} date
|
|
|
|
* @returns {string|undefined} Formatted date or undefined for non-Date
|
|
|
|
*/
|
|
|
|
export const formatDay = (date) => {
|
2022-11-26 14:50:59 +01:00
|
|
|
if (!date instanceof Date) return;
|
2022-10-22 16:14:21 +02:00
|
|
|
|
2022-12-04 12:00:18 +01:00
|
|
|
const year = String(date.getFullYear());
|
|
|
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
|
|
const day = String(date.getDate()).padStart(2, '0');
|
|
|
|
|
|
|
|
return `${year}-${month}-${day}`;
|
2022-12-22 18:28:51 +01:00
|
|
|
};
|