fix(core): parse date utils (#10789)

* fix(core): parse date utils

* fix: regex
This commit is contained in:
Tony
2022-09-14 18:59:32 +05:00
committed by GitHub
parent d553430312
commit 6251a2dc02
2 changed files with 8 additions and 4 deletions

View File

@@ -70,19 +70,19 @@ const patterns = [
}, },
{ {
unit: 'days', unit: 'days',
regExp: /(\d+)(?:天|日|day(?:s)?)/, regExp: /(\d+)(?:天|日|d(?:ay)?(?:s)?)/,
}, },
{ {
unit: 'hours', unit: 'hours',
regExp: /(\d+)(?:(?:个|個)?(?:(?:小)?时|時|点|點)|h(?:ou)?r(?:s)?)/, regExp: /(\d+)(?:(?:个|個)?(?:(?:小)?时|時|点|點)|h(?:(?:ou)?r)?(?:s)?)/,
}, },
{ {
unit: 'minutes', unit: 'minutes',
regExp: /(\d+)(?:分(?:钟|鐘)?|min(?:ute)?(?:s)?)/, regExp: /(\d+)(?:分(?:钟|鐘)?|m(?:in(?:ute)?)?(?:s)?)/,
}, },
{ {
unit: 'seconds', unit: 'seconds',
regExp: /(\d+)(?:秒(?:钟|鐘)?|sec(?:ond)?(?:s)?)/, regExp: /(\d+)(?:秒(?:钟|鐘)?|s(?:ec(?:ond)?)?(?:s)?)/,
}, },
]; ];

View File

@@ -100,6 +100,10 @@ describe('parseRelativeDate', () => {
expect(+new Date(parseRelativeDate('1小时1分钟1秒钟前'))).toBe(+date - 1 * hour - 1 * minute - 1 * second); 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秒钟后', () => { it('H小时m分钟s秒钟后', () => {
expect(+new Date(parseRelativeDate('1小时1分钟1秒钟后'))).toBe(+date + 1 * hour + 1 * minute + 1 * second); expect(+new Date(parseRelativeDate('1小时1分钟1秒钟后'))).toBe(+date + 1 * hour + 1 * minute + 1 * second);
}); });