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-10-22 16:14:21 +02:00
|
|
|
|
2022-11-26 14:50:59 +01:00
|
|
|
return String(date.getHours()).padStart(2, '0') + ':'
|
2022-10-22 16:14:21 +02:00
|
|
|
+ String(date.getMinutes()).padStart(2, '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-11-26 14:50:59 +01:00
|
|
|
return String(date.getFullYear()) + '-'
|
2022-10-22 16:14:21 +02:00
|
|
|
+ String(date.getMonth() + 1).padStart(2, '0') + '-'
|
|
|
|
+ String(date.getDate()).padStart(2, '0');
|
|
|
|
}
|