(timestamp: number, [unit, step]: TimeInterval)
| 315 | }; |
| 316 | |
| 317 | const floorTime = (timestamp: number, [unit, step]: TimeInterval): number => { |
| 318 | const date = dateNew(timestamp); |
| 319 | const year = dateGetUTCFullYear(date); |
| 320 | const month = dateGetUTCMonth(date); |
| 321 | const monthStep = unit == QUARTER_UNIT ? step * 3 : step; |
| 322 | const monthIndex = year * 12 + month; |
| 323 | const flooredMonthIndex = mathFloor(monthIndex / monthStep) * monthStep; |
| 324 | const fixedInterval = getFixedInterval(unit, step); |
| 325 | return unit == YEAR_UNIT |
| 326 | ? dateUtc(mathFloor(year / step) * step, 0, 1) |
| 327 | : unit == QUARTER_UNIT || unit == MONTH_UNIT |
| 328 | ? dateUtc(mathFloor(flooredMonthIndex / 12), flooredMonthIndex % 12, 1) |
| 329 | : unit == WEEK_UNIT |
| 330 | ? dateUtc(year, month, dateGetUTCDate(date)) - |
| 331 | ((dateGetUTCDay(date) + 6) % 7) * DAY |
| 332 | : mathFloor(timestamp / fixedInterval) * fixedInterval; |
| 333 | }; |
| 334 | |
| 335 | const addTime = (timestamp: number, [unit, step]: TimeInterval): number => { |
| 336 | const date = dateNew(timestamp); |
no test coverage detected
searching dependent graphs…