import {describe, it, expect} from 'vitest'; import {Instant} from '@/'; describe('Instant', () => { describe('#round', () => { it('with string as option', async () => { let instant = Instant.fromEpochMilliseconds(1709910237265); expect(instant.toString()).toEqual('2024-03-08T15:03:57.265Z'); expect(instant.round('second').toString()).toEqual('2024-03-08T15:03:57.000Z'); expect(instant.round('minute').toString()).toEqual('2024-03-08T15:04:00.000Z'); expect(instant.round('hour').toString()).toEqual('2024-03-08T15:00:00.000Z'); }); it('rounds using rounding increment', async () => { let instant = Instant.fromEpochMilliseconds(1709910237265); expect(instant.toString()).toEqual('2024-03-08T15:03:57.265Z'); expect(instant.round({smallestUnit: 'second', roundingIncrement: 5}).toString()).toEqual( '2024-03-08T15:03:55.000Z', ); expect(instant.round({smallestUnit: 'minute', roundingIncrement: 10}).toString()).toEqual( '2024-03-08T15:00:00.000Z', ); expect(instant.round({smallestUnit: 'hour', roundingIncrement: 6}).toString()).toEqual( '2024-03-08T18:00:00.000Z', ); }); }); });