fix: correct case-sensitivity in duedate time parsing (#1613)
Co-authored-by: mechanarchy <1166756+mechanarchy@users.noreply.github.com>
This commit is contained in:
parent
22baaf2bbb
commit
c2e224dbb1
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue