anki/ts/lib/time.test.ts
Damien Elmes 9440898e60 add naturalWholeUnit() and basic tests to lib/time.ts
naturalWholeUnit() is not currently used
2021-04-12 14:42:06 +10:00

26 lines
1.3 KiB
TypeScript

import { naturalUnit, naturalWholeUnit, TimespanUnit } from "./time";
test("natural unit", () => {
expect(naturalUnit(5)).toBe(TimespanUnit.Seconds);
expect(naturalUnit(59)).toBe(TimespanUnit.Seconds);
expect(naturalUnit(60)).toBe(TimespanUnit.Minutes);
expect(naturalUnit(60 * 60 - 1)).toBe(TimespanUnit.Minutes);
expect(naturalUnit(60 * 60)).toBe(TimespanUnit.Hours);
expect(naturalUnit(60 * 60 * 24)).toBe(TimespanUnit.Days);
expect(naturalUnit(60 * 60 * 24 * 30)).toBe(TimespanUnit.Months);
});
test("natural whole unit", () => {
expect(naturalWholeUnit(5)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(59)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(60)).toBe(TimespanUnit.Minutes);
expect(naturalWholeUnit(61)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(90)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(60 * 60 - 1)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(60 * 60 + 1)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(60 * 60)).toBe(TimespanUnit.Hours);
expect(naturalWholeUnit(24 * 60 * 60 - 1)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(24 * 60 * 60 + 1)).toBe(TimespanUnit.Seconds);
expect(naturalWholeUnit(24 * 60 * 60)).toBe(TimespanUnit.Days);
});