mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
fix(utils): parse relative date with meridiem (#9775)
* fix(utils): parse relative date with meridiem * fix: use regex
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user