|
1 | | -import { insertPaddingPointsForChart } from './utils'; |
| 1 | +import { insertPaddingPointsForChart, roundDateToInterval } from './utils'; |
2 | 2 |
|
3 | 3 | describe('insertPaddingPointsForChart', () => { |
4 | 4 | describe('edge cases', () => { |
@@ -287,3 +287,29 @@ describe('insertPaddingPointsForChart', () => { |
287 | 287 | }); |
288 | 288 | }); |
289 | 289 | }); |
| 290 | + |
| 291 | +describe('roundDateToInterval', () => { |
| 292 | + describe('exact 5-minute boundaries', () => { |
| 293 | + it('should return unchanged date for 23:55:00', () => { |
| 294 | + const date = new Date('2026-01-26T23:55:00.000Z'); |
| 295 | + const rounded = roundDateToInterval(date); |
| 296 | + expect(rounded.getTime()).toBe(date.getTime()); |
| 297 | + }); |
| 298 | + }); |
| 299 | + |
| 300 | + describe('rounding to nearest 5-minute boundary', () => { |
| 301 | + it('should round 22:57:00 down to 22:55:00', () => { |
| 302 | + const date = new Date('2026-01-26T22:57:00.000Z'); |
| 303 | + const rounded = roundDateToInterval(date); |
| 304 | + const expected = new Date('2026-01-26T22:55:00.000Z'); |
| 305 | + expect(rounded.getTime()).toBe(expected.getTime()); |
| 306 | + }); |
| 307 | + |
| 308 | + it('should round 22:59:00 up to 23:00:00', () => { |
| 309 | + const date = new Date('2026-01-26T22:59:00.000Z'); |
| 310 | + const rounded = roundDateToInterval(date); |
| 311 | + const expected = new Date('2026-01-26T23:00:00.000Z'); |
| 312 | + expect(rounded.getTime()).toBe(expected.getTime()); |
| 313 | + }); |
| 314 | + }); |
| 315 | +}); |
0 commit comments