MCPcopy Create free account
hub / github.com/tinyplex/tinybase / floorTime

Function floorTime

src/ui-react-dom-charts/common/wilkinson.ts:317–333  ·  view source on GitHub ↗
(timestamp: number, [unit, step]: TimeInterval)

Source from the content-addressed store, hash-verified

315};
316
317const 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
335const addTime = (timestamp: number, [unit, step]: TimeInterval): number => {
336 const date = dateNew(timestamp);

Callers 1

getTimeTicksFunction · 0.70

Calls 6

dateNewFunction · 0.90
dateGetUTCFullYearFunction · 0.90
dateGetUTCMonthFunction · 0.90
dateGetUTCDateFunction · 0.90
dateGetUTCDayFunction · 0.90
getFixedIntervalFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…