fix: correct case-sensitivity in duedate time parsing (#1613)

Co-authored-by: mechanarchy <1166756+mechanarchy@users.noreply.github.com>
This commit is contained in:
kolaente 2025-10-08 18:24:54 +02:00 committed by GitHub
parent 22baaf2bbb
commit c2e224dbb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -109,7 +109,7 @@ const addTimeToDate = (text: string, date: Date, previousMatch: string | null):
}
}
const timeRegex = ' (at|@) ([0-9][0-9]?(:[0-9][0-9]?)?( ?(a|p)m)?)'
const timeRegex = ' (at|@) ([0-9][0-9]?(:[0-9][0-9])?( ?(a|p)m)?)'
const matcher = new RegExp(timeRegex, 'ig')
const results = matcher.exec(text)
@ -118,7 +118,7 @@ const addTimeToDate = (text: string, date: Date, previousMatch: string | null):
const parts = time.split(':')
let hours = parseInt(parts[0])
let minutes = 0
if (time.endsWith('pm')) {
if (time.toLowerCase().endsWith('pm')) {
hours += 12
}
if (parts.length > 1) {
@ -128,6 +128,7 @@ const addTimeToDate = (text: string, date: Date, previousMatch: string | null):
date.setHours(hours)
date.setMinutes(minutes)
date.setSeconds(0)
date.setMilliseconds(0)
}
const replace = results !== null ? results[0] : previousMatch

View File

@ -96,6 +96,10 @@ describe('Parse Task Text', () => {
'at 3am': '3:0',
'at 3:12 am': '3:12',
'at 3:12 pm': '15:12',
'at 3:12 AM': '3:12',
'at 3:12 PM': '15:12',
'at 3:12 Am': '3:12',
'at 3:12 Pm': '15:12',
} as const
for (const c in cases) {