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

Function getDateArray

src/client/utils/date.ts:28–54  ·  view source on GitHub ↗
(
  data: { x: string; y: number }[],
  startDate: dayjs.ConfigType,
  endDate: dayjs.ConfigType,
  unit: DateUnit
)

Source from the content-addressed store, hash-verified

26 * replace with `@tianji/shared`
27 */
28export function getDateArray(
29 data: { x: string; y: number }[],
30 startDate: dayjs.ConfigType,
31 endDate: dayjs.ConfigType,
32 unit: DateUnit
33) {
34 const arr = [];
35 const { diff, add, normalize } = createDateUnitFn(unit);
36 const n = diff(endDate, startDate) + 1;
37
38 function findData(date: dayjs.Dayjs) {
39 const d = data.find(({ x }) => {
40 return normalize(dayjs(x)).unix() === date.unix();
41 });
42
43 return d?.y || 0;
44 }
45
46 for (let i = 0; i < n; i++) {
47 const t = normalize(add(startDate, i));
48 const y = findData(t);
49
50 arr.push({ x: formatDate(t), y });
51 }
52
53 return arr;
54}
55
56export function formatDate(val: dayjs.ConfigType) {
57 return dayjs(val).format('YYYY-MM-DD HH:mm:ss');

Callers 1

selectFunction · 0.90

Calls 3

findDataFunction · 0.85
createDateUnitFnFunction · 0.70
formatDateFunction · 0.70

Tested by

no test coverage detected