import { formatDateTimeTZ, formatDateTZ, getIsoWeek, addMonths, addHours, addMinutes, differentMonth, differentSecond, differentMin, getHourRange, } from './date.util'; describe('formatDateTimeTZ', () => { it('should format date with timezone', () => { const date = new Date('2022-01-01T00:00:00Z'); const timezone = 'America/New_York'; const formattedDate = formatDateTimeTZ(date, timezone); expect(formattedDate).toBe('31-12-2021 07:00:00 -05:00'); }); }); describe('formatDateTZ', () => { it('should format date with timezone', () => { const date = new Date('2022-01-01T00:00:00Z'); const timezone = 'America/New_York'; const formattedDate = formatDateTZ(date, timezone); expect(formattedDate).toBe('2021-12-31'); }); }); describe('getIsoWeek', () => { it('should return the ISO week and year', () => { const { year } = getIsoWeek(); const currentYear = new Date().getFullYear(); expect(year).toBe(currentYear); }); }); describe('addMonths', () => { it('should add specified number of months to the date', () => { const date = new Date('2022-01-01T00:00:00Z'); const months = 3; const newDate = addMonths(date, months); const expectedDate = new Date('2022-04-01T00:00:00Z'); expect(newDate).toEqual(expectedDate); }); }); describe('addHours', () => { it('should add specified number of hours to the date', () => { const date = new Date('2022-01-01T00:00:00Z'); const hours = 2; const newDate = addHours(date, hours); const expectedDate = new Date('2022-01-01T02:00:00Z'); expect(newDate).toEqual(expectedDate); }); }); describe('addMinutes', () => { it('should add specified number of minutes to the date', () => { const date = new Date('2022-01-01T00:00:00Z'); const minutes = 30; const newDate = addMinutes(date, minutes); const expectedDate = new Date('2022-01-01T00:30:00Z'); expect(newDate).toEqual(expectedDate); }); }); describe('differentMonth', () => { it('should return the difference in months between two dates', () => { const date1 = new Date('2022-01-01T00:00:00Z'); const date2 = new Date('2022-04-01T00:00:00Z'); const difference = differentMonth(date2, date1); expect(difference).toBe(3); }); }); describe('differentSecond', () => { it('should return the difference in seconds between two dates', () => { const date1 = new Date('2022-01-01T00:00:00Z'); const date2 = new Date('2022-01-01T00:00:10Z'); const difference = differentSecond(date2, date1); expect(difference).toBe(10); }); }); describe('differentMin', () => { it('should return the difference in minutes between two dates', () => { const date1 = new Date('2022-01-01T00:00:00Z'); const date2 = new Date('2022-01-01T00:10:00Z'); const difference = differentMin(date2, date1); expect(difference).toBe(10); }); }); describe('getHourRange', () => { it('should return the range of hours for the given date', () => { const date = new Date('2022-01-01T12:30:00Z'); const { begin, end } = getHourRange(date); const expectedBegin = new Date('2022-01-01T12:00:00Z'); const expectedEnd = new Date('2022-01-01T12:59:59.999Z'); expect(begin).toEqual(expectedBegin); expect(end).toEqual(expectedEnd); }); });