MCPcopy Index your code
hub / github.com/apache/echarts / getUnitFromValue

Function getUnitFromValue

src/util/time.ts:370–410  ·  view source on GitHub ↗
(
    value: number | string | Date,
    isUTC: boolean
)

Source from the content-addressed store, hash-verified

368}
369
370export function getUnitFromValue(
371 value: number | string | Date,
372 isUTC: boolean
373): PrimaryTimeUnit {
374 const date = numberUtil.parseDate(value);
375 const M = (date as any)[monthGetterName(isUTC)]() + 1;
376 const d = (date as any)[dateGetterName(isUTC)]();
377 const h = (date as any)[hoursGetterName(isUTC)]();
378 const m = (date as any)[minutesGetterName(isUTC)]();
379 const s = (date as any)[secondsGetterName(isUTC)]();
380 const S = (date as any)[millisecondsGetterName(isUTC)]();
381
382 const isSecond = S === 0;
383 const isMinute = isSecond && s === 0;
384 const isHour = isMinute && m === 0;
385 const isDay = isHour && h === 0;
386 const isMonth = isDay && d === 1;
387 const isYear = isMonth && M === 1;
388
389 if (isYear) {
390 return 'year';
391 }
392 else if (isMonth) {
393 return 'month';
394 }
395 else if (isDay) {
396 return 'day';
397 }
398 else if (isHour) {
399 return 'hour';
400 }
401 else if (isMinute) {
402 return 'minute';
403 }
404 else if (isSecond) {
405 return 'second';
406 }
407 else {
408 return 'millisecond';
409 }
410}
411
412// export function getUnitValue(
413// value: number | Date,

Callers 3

getTicksMethod · 0.90
createIntervalTicksFunction · 0.90
leveledFormatFunction · 0.85

Calls 6

monthGetterNameFunction · 0.85
dateGetterNameFunction · 0.85
hoursGetterNameFunction · 0.85
minutesGetterNameFunction · 0.85
secondsGetterNameFunction · 0.85
millisecondsGetterNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…