diff --git a/lib/utils/parse-date.js b/lib/utils/parse-date.js index f19cf1fbbd..2412432a98 100644 --- a/lib/utils/parse-date.js +++ b/lib/utils/parse-date.js @@ -129,7 +129,7 @@ module.exports = { // 将 `\d+年\d+月...\d+秒前` 分割成 `['\d+年', ..., '\d+秒前']` - const matches = theDate.match(/(?:\D+)?\d+(?!:|-|\/)\D+/g); + const matches = theDate.match(/(?:\D+)?\d+(?!:|-|\/|(a|p)m)\D+/g); if (matches) { // 获得最后的时间单元,如 `\d+秒前` @@ -187,7 +187,9 @@ module.exports = { for (const w of words) { const wordMatches = w.regExp.exec(theDate); if (wordMatches) { - return dayjs(`${w.startAt.format('YYYY-MM-DD')} ${wordMatches[1]}`).toDate(); + // The default parser of dayjs() can parse '8:00 pm' but not '8:00pm' + // so we need to insert a space in between + return dayjs(`${w.startAt.format('YYYY-MM-DD')} ${/a|pm$/.test(wordMatches[1]) ? wordMatches[1].replace(/a|pm/, ' $&') : wordMatches[1]}`).toDate(); } } } diff --git a/test/utils/parse-date.js b/test/utils/parse-date.js index 87e170ffe2..682b911851 100644 --- a/test/utils/parse-date.js +++ b/test/utils/parse-date.js @@ -112,6 +112,10 @@ describe('parseRelativeDate', () => { expect(+new Date(parseRelativeDate('Today 08:00'))).toBe(+date + 8 * hour); }); + it('Today, h:m a', () => { + expect(+new Date(parseRelativeDate('Today, 8:00 pm'))).toBe(+date + 20 * hour); + }); + it('TDA H:m:s', () => { expect(+new Date(parseRelativeDate('TDA 08:00:00'))).toBe(+date + 8 * hour); });