UNPKG

lunisolar

Version:

专业农历库,支持公历阴历互转,支持各类黄历数据查询,如八字四柱、阴历、神煞宜忌、时辰吉凶、建除十二神、胎神占方、五行纳音等。支持自定义插件。

42 lines (36 loc) 1.44 kB
import * as U from '../../src/utils' import * as C from '../../src/constants' import { Lunisolar } from '../../src/class/lunisolar' function formatDate(date: Date) { return `${date.getFullYear()}-${ date.getMonth() + 1 }-${date.getDate()} ${date.getHours()}:${date.getMinutes()}` } describe('utils', () => { it('test prettyUnit', () => { for (const unit in C.UNITS) { expect(U.prettyUnit(unit as any)).toBe((C.UNITS as any)[unit]) } expect(U.prettyUnit('Millisecond' as any)).toBe('millisecond') }) it('test parseDate', () => { const date = new Date() expect(U.parseDate(date)).toEqual(date) expect(U.parseDate(new Lunisolar(date))).toEqual(date) expect(U.parseDate(null).toString()).toBe('Invalid Date') expect(Math.floor(U.parseDate(undefined).valueOf() / 10000)).toEqual( Math.floor(new Date().valueOf() / 10000) ) expect(U.parseDate('2020-01-01')).toEqual(new Date('2020/01/01 00:00:00')) expect(U.parseDate('2020-01-01T12:00:00.000Z')).toEqual(new Date('2020-01-01T12:00:00.000Z')) }) it('test parseDate utc', () => { const date = U.parseDate('2023-03-14 15:57', true) expect(formatDate(date)).toEqual('2023-3-14 23:57') }) it('computeSBMonthValueByTerm', () => { const date = U.parseDate('2018-12-06') const msbValue = U.computeSBMonthValueByTerm(date, 20, U.parseDate('2018-11-06T16:00:00.000Z')) expect(msbValue).toBe(59) }) })