diff --git a/lib/utils/parse-date.js b/lib/utils/parse-date.js index 2412432a98..b0b0e1b9dc 100644 --- a/lib/utils/parse-date.js +++ b/lib/utils/parse-date.js @@ -70,19 +70,19 @@ const patterns = [ }, { unit: 'days', - regExp: /(\d+)(?:天|日|day(?:s)?)/, + regExp: /(\d+)(?:天|日|d(?:ay)?(?:s)?)/, }, { unit: 'hours', - regExp: /(\d+)(?:(?:个|個)?(?:(?:小)?时|時|点|點)|h(?:ou)?r(?:s)?)/, + regExp: /(\d+)(?:(?:个|個)?(?:(?:小)?时|時|点|點)|h(?:(?:ou)?r)?(?:s)?)/, }, { unit: 'minutes', - regExp: /(\d+)(?:分(?:钟|鐘)?|min(?:ute)?(?:s)?)/, + regExp: /(\d+)(?:分(?:钟|鐘)?|m(?:in(?:ute)?)?(?:s)?)/, }, { unit: 'seconds', - regExp: /(\d+)(?:秒(?:钟|鐘)?|sec(?:ond)?(?:s)?)/, + regExp: /(\d+)(?:秒(?:钟|鐘)?|s(?:ec(?:ond)?)?(?:s)?)/, }, ]; diff --git a/test/utils/parse-date.js b/test/utils/parse-date.js index 682b911851..d1dc703f82 100644 --- a/test/utils/parse-date.js +++ b/test/utils/parse-date.js @@ -100,6 +100,10 @@ describe('parseRelativeDate', () => { expect(+new Date(parseRelativeDate('1小时1分钟1秒钟前'))).toBe(+date - 1 * hour - 1 * minute - 1 * second); }); + it('Dd Hh mm ss ago', () => { + expect(+new Date(parseRelativeDate('1d 1h 1m 1s ago'))).toBe(+date - 1 * day - 1 * hour - 1 * minute - 1 * second); + }); + it('H小时m分钟s秒钟后', () => { expect(+new Date(parseRelativeDate('1小时1分钟1秒钟后'))).toBe(+date + 1 * hour + 1 * minute + 1 * second); });