diff --git a/packages/koishi-utils/src/date.ts b/packages/koishi-utils/src/date.ts index 21077075e4..8131415c28 100644 --- a/packages/koishi-utils/src/date.ts +++ b/packages/koishi-utils/src/date.ts @@ -1,4 +1,5 @@ -export function getDateNumber (date = new Date()) { +export function getDateNumber (date: number | Date = new Date()) { + if (typeof date === 'number') date = new Date(date) return Math.floor(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / 86400000) } diff --git a/packages/koishi-utils/tests/date.spec.ts b/packages/koishi-utils/tests/date.spec.ts index d4d522d825..0df05f29cb 100644 --- a/packages/koishi-utils/tests/date.spec.ts +++ b/packages/koishi-utils/tests/date.spec.ts @@ -4,6 +4,7 @@ describe('Date Manipulations', () => { test('getDateNumber', () => { getDateNumber() /* make coverage happy */ expect(getDateNumber(new Date(2020, 0))).toBe(18262) + expect(getDateNumber(1577808000000)).toBe(18262) }) test('fromDateNumber', () => {