mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 04:11:26 +08:00
fix(core): parse date utils (#10789)
* fix(core): parse date utils * fix: regex
This commit is contained in:
@@ -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)?)/,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user