MCPcopy
hub / github.com/msgbyte/tianji / getMinimumUnit

Function getMinimumUnit

src/shared/src/date.ts:10–25  ·  view source on GitHub ↗
(
  startDate: ConfigType,
  endDate: ConfigType
)

Source from the content-addressed store, hash-verified

8export type DateUnit = 'minute' | 'hour' | 'day' | 'month' | 'year';
9
10export function getMinimumUnit(
11 startDate: ConfigType,
12 endDate: ConfigType
13): DateUnit {
14 if (dayjs(endDate).diff(startDate, 'minutes') <= 60) {
15 return 'minute';
16 } else if (dayjs(endDate).diff(startDate, 'hours') <= 48) {
17 return 'hour';
18 } else if (dayjs(endDate).diff(startDate, 'days') <= 90) {
19 return 'day';
20 } else if (dayjs(endDate).diff(startDate, 'months') <= 24) {
21 return 'month';
22 }
23
24 return 'year';
25}
26
27function createDateUnitFn(unit: DateUnit, timezone?: string) {
28 if (timezone) {

Callers 4

useGlobalRangeDateFunction · 0.90
date.spec.tsFile · 0.90
parseDateRangeFunction · 0.90
getAllowedUnitsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected