mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
test: date cases
This commit is contained in:
+3
-3
@@ -41,6 +41,9 @@ module.exports = (html, timeZone = -serverOffset) => {
|
||||
} else if (/(\d+)-(\d+) (\d+):(\d+)/.exec(html)) {
|
||||
math = /(\d+)-(\d+) (\d+):(\d+)/.exec(html);
|
||||
date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2], math[3], math[4]);
|
||||
} else if (/(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+):(\d+)/.exec(html)) {
|
||||
math = /(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+):(\d+)/.exec(html);
|
||||
date = new Date(math[1], parseInt(math[2]) - 1, math[3], math[4], math[5], math[6]);
|
||||
} else if (/(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html)) {
|
||||
math = /(\d+)\/(\d+)\/(\d+)\s*(\d+):(\d+)/.exec(html);
|
||||
date = new Date(math[1], parseInt(math[2]) - 1, math[3], math[4], math[5]);
|
||||
@@ -59,9 +62,6 @@ module.exports = (html, timeZone = -serverOffset) => {
|
||||
} else if (/(\d+)-(\d+)/.exec(html)) {
|
||||
math = /(\d+)-(\d+)/.exec(html);
|
||||
date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2]);
|
||||
} else if (/(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/.exec(html)) {
|
||||
math = /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/.exec(html);
|
||||
date = new Date(math[1], parseInt(math[2]) - 1, math[3], math[4], math[5], math[6]);
|
||||
} else if (/(\d+):(\d+)/.exec(html)) {
|
||||
math = /(\d+):(\d+)/.exec(html);
|
||||
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), math[1], math[2]);
|
||||
|
||||
+21
-2
@@ -42,6 +42,10 @@ describe('date', () => {
|
||||
expect(+new Date(parseDate('2018年4月2日1时'))).toBe(+new Date('2018-4-2 01:00'));
|
||||
});
|
||||
|
||||
it('Y年M月D日', async () => {
|
||||
expect(+new Date(parseDate('2018年4月2日'))).toBe(+new Date('2018-4-2 00:00'));
|
||||
});
|
||||
|
||||
it('Y-M-D H:m', async () => {
|
||||
expect(+new Date(parseDate('2018-4-2 02:03'))).toBe(+new Date('2018-4-2 02:03'));
|
||||
});
|
||||
@@ -50,6 +54,10 @@ describe('date', () => {
|
||||
expect(+new Date(parseDate('2-3 02:03'))).toBe(+new Date('2019-2-3 02:03'));
|
||||
});
|
||||
|
||||
it('Y/M/D H:m:s', async () => {
|
||||
expect(+new Date(parseDate('2018/4/2 02:03:04'))).toBe(+new Date('2018-4-2 02:03:04'));
|
||||
});
|
||||
|
||||
it('Y/M/D H:m', async () => {
|
||||
expect(+new Date(parseDate('2018/4/2 02:03'))).toBe(+new Date('2018-4-2 02:03'));
|
||||
});
|
||||
@@ -62,6 +70,10 @@ describe('date', () => {
|
||||
expect(+new Date(parseDate('2月3日 02:03'))).toBe(+new Date('2019-2-3 02:03'));
|
||||
});
|
||||
|
||||
it('M月D日', async () => {
|
||||
expect(+new Date(parseDate('2月3日'))).toBe(+new Date('2019-2-3 00:00'));
|
||||
});
|
||||
|
||||
it('Y-M-D', async () => {
|
||||
expect(+new Date(parseDate('2018-4-2'))).toBe(+new Date('2018-4-2'));
|
||||
});
|
||||
@@ -70,8 +82,15 @@ describe('date', () => {
|
||||
expect(+new Date(parseDate('4-2'))).toBe(+new Date('2019-4-2'));
|
||||
});
|
||||
|
||||
it('H:m', async () => {
|
||||
expect(+new Date(parseDate('02:03'))).toBe(+new Date('2019-1-1 02:03'));
|
||||
it('M-D', async () => {
|
||||
expect(+new Date(parseDate('4-2'))).toBe(+new Date('2019-4-2'));
|
||||
});
|
||||
|
||||
it('刚刚', async () => {
|
||||
const result = +new Date(parseDate('刚刚'));
|
||||
const now = +new Date();
|
||||
expect(result - now).toBeLessThan(10);
|
||||
expect(result - now).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('Invalid', async () => {
|
||||
|
||||
Reference in New Issue
Block a user