mirror of https://kolaente.dev/vikunja/api.git
feat: Add isoToKebabDatetime helper
This commit is contained in:
parent
9e2a6d5575
commit
d183fafa1e
|
@ -0,0 +1,19 @@
|
|||
import type {DateISO} from '@/types/DateISO'
|
||||
import type {DatetimeKebab} from '@/types/DatetimeKebab'
|
||||
|
||||
// ✅ Format a date to YYYY-MM-DD HH:MM
|
||||
function padTo2Digits(num: number) {
|
||||
return num.toString().padStart(2, '0')
|
||||
}
|
||||
|
||||
export function isoToKebabDatetime(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('-') + ' ' + [
|
||||
padTo2Digits(date.getHours()),
|
||||
padTo2Digits(date.getMinutes()),
|
||||
].join(':') as DatetimeKebab
|
||||
}
|
Loading…
Reference in New Issue