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

Function getTimeTickLabel

src/ui-react-dom-charts/common/wilkinson.ts:277–315  ·  view source on GitHub ↗
(
  timestamp: number,
  ticks: number[],
)

Source from the content-addressed store, hash-verified

275};
276
277export const getTimeTickLabel = (
278 timestamp: number,
279 ticks: number[],
280): string => {
281 const date = dateNew(timestamp);
282 const year = dateGetUTCFullYear(date) + EMPTY_STRING;
283 const month = getPadded(dateGetUTCMonth(date) + 1);
284 const day = getPadded(dateGetUTCDate(date));
285 const hour = getPadded(dateGetUTCHours(date));
286 const minute = getPadded(dateGetUTCMinutes(date));
287 const second = getPadded(dateGetUTCSeconds(date));
288 const dateLabel = `${year}-${month}-${day}`;
289 let minDiff = infinity;
290 arrayForEach(ticks, (tick, index) => {
291 if (index > 0) {
292 minDiff = mathMin(minDiff, tick - ticks[index - 1]);
293 }
294 });
295 minDiff =
296 minDiff == infinity
297 ? dateGetUTCHours(date) == 0 &&
298 dateGetUTCMinutes(date) == 0 &&
299 dateGetUTCSeconds(date) == 0
300 ? DAY
301 : dateGetUTCSeconds(date) == 0
302 ? HOUR
303 : SECOND
304 : minDiff;
305
306 return minDiff < MINUTE
307 ? `${dateLabel} ${hour}:${minute}:${second}`
308 : minDiff < DAY
309 ? `${dateLabel} ${hour}:${minute}`
310 : minDiff < MONTH
311 ? dateLabel
312 : minDiff < YEAR
313 ? `${year}-${month}`
314 : year;
315};
316
317const floorTime = (timestamp: number, [unit, step]: TimeInterval): number => {
318 const date = dateNew(timestamp);

Callers 1

getTickLabelFunction · 0.90

Calls 9

dateNewFunction · 0.90
dateGetUTCFullYearFunction · 0.90
dateGetUTCMonthFunction · 0.90
dateGetUTCDateFunction · 0.90
dateGetUTCHoursFunction · 0.90
dateGetUTCMinutesFunction · 0.90
dateGetUTCSecondsFunction · 0.90
arrayForEachFunction · 0.90
getPaddedFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…