This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/time/isoToKebabDate.ts

16 lines
484 B
TypeScript

import type {DateISO} from '@/types/DateISO'
import type {DateKebab} from '@/types/DateKebab'
// ✅ Format a date to YYYY-MM-DD (or any other format)
function padTo2Digits(num: number) {
return num.toString().padStart(2, '0')
}
export function isoToKebabDate(isoDate: DateISO) {
const date = new Date(isoDate)
return [
date.getFullYear(),
padTo2Digits(date.getMonth() + 1), // January is 0, but we want it to be 1
padTo2Digits(date.getDate()),
].join('-') as DateKebab
}