mirror of
https://github.com/Steffo99/todocolors.git
synced 2024-10-16 07:17:28 +00:00
Fix dates
This commit is contained in:
parent
74b3336ea1
commit
0f5fdb038b
1 changed files with 23 additions and 4 deletions
|
@ -4,9 +4,15 @@ import {ICON_DEFAULT, ICON_GLYPH_RE} from "@/app/[lang]/board/[board]/(page)/(ed
|
|||
import {IMPORTANCE_GLYPH_RE} from "@/app/[lang]/board/[board]/(page)/(edit)/taskImportance"
|
||||
import {default as dateParser} from "any-date-parser"
|
||||
|
||||
// ahhh i love typescript shenanigans
|
||||
// @ts-ignore
|
||||
const DATE_FROM_STRING = dateParser.fromString;
|
||||
type Attempt = {
|
||||
year?: number,
|
||||
month?: number,
|
||||
day?: number,
|
||||
hour?: number,
|
||||
minute?: number,
|
||||
second?: number,
|
||||
millisecond?: number,
|
||||
}
|
||||
|
||||
const VALUE_TO_TASK_IMPORTANCE = {
|
||||
"1": TaskImportance.Highest,
|
||||
|
@ -23,9 +29,22 @@ export function convertSTT(text: string, lang: string): Task {
|
|||
|
||||
const importance: TaskImportance = VALUE_TO_TASK_IMPORTANCE[importanceMatch?.[1]?.trim() as "1"|"2"|"3"|"4"|"5" ?? "3"]
|
||||
const icon: string = iconMatch?.[1]?.trim() ?? ICON_DEFAULT
|
||||
|
||||
const now = new Date()
|
||||
const deadlineGroup: string | undefined = deadlineMatch?.[1]?.trim()
|
||||
const deadlineDate: Date | undefined = deadlineGroup === undefined ? undefined : DATE_FROM_STRING(deadlineGroup, lang) ?? undefined
|
||||
const deadlineAttempt: Attempt | undefined = deadlineGroup === undefined ? undefined : dateParser.attempt(deadlineGroup, lang) ?? undefined
|
||||
const deadlineDate: Date | undefined = deadlineAttempt === undefined ? undefined : new Date(
|
||||
deadlineAttempt.year ?? now.getFullYear(),
|
||||
(deadlineAttempt.month ?? (now.getMonth() + 1)) - 1,
|
||||
deadlineAttempt.day ?? now.getDate(),
|
||||
deadlineAttempt.hour ?? now.getHours(),
|
||||
deadlineAttempt.minute ?? now.getMinutes(),
|
||||
deadlineAttempt.second ?? now.getSeconds(),
|
||||
deadlineAttempt.millisecond ?? now.getMilliseconds(),
|
||||
)
|
||||
const deadline: number | null = (deadlineDate?.getTime?.()) ?? null
|
||||
|
||||
console.debug("[convertSTT]", "\ngroup:", deadlineGroup, "\ndate:", deadlineDate, "\ntimestamp:", deadline)
|
||||
|
||||
// TODO: Splice so the regexes aren't executed twice
|
||||
text = text.replace(IMPORTANCE_GLYPH_RE, "")
|
||||
|
|
Loading…
Reference in a new issue