feat: refine task and countdown interactions
This commit is contained in:
@@ -217,6 +217,22 @@ export function defaultTaskDueAt(now = new Date()) {
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
export type TaskDueDraft = { date: string; hasTime: boolean; time: string }
|
||||
|
||||
export function parseTaskDueDraft(value: string | null | undefined, dueHasTime: boolean): TaskDueDraft {
|
||||
const local = toDateTimeLocal(value)
|
||||
if (!local) return { date: '', hasTime: false, time: '12:00' }
|
||||
const [date, time = '12:00'] = local.split('T')
|
||||
return { date, hasTime: dueHasTime, time: dueHasTime ? time : '12:00' }
|
||||
}
|
||||
|
||||
export function buildTaskDueDraft(draft: TaskDueDraft) {
|
||||
if (!draft.date) return { due_at: null, due_has_time: false }
|
||||
const hasTime = draft.hasTime && Boolean(draft.time)
|
||||
const local = `${draft.date}T${hasTime ? draft.time : '23:59'}`
|
||||
return { due_at: fromDateTimeLocal(local), due_has_time: hasTime }
|
||||
}
|
||||
|
||||
export function toDateTimeLocal(value: string | null | undefined) {
|
||||
if (!value) return ''
|
||||
const date = new Date(value)
|
||||
|
||||
Reference in New Issue
Block a user