BUR-62 переработана отрисовка графика на отрезки по грануляции

This commit is contained in:
Первов Артем
2026-07-05 09:54:05 +03:00
parent 772ba60647
commit 1a994f36bd
6 changed files with 141 additions and 84 deletions

View File

@@ -25,6 +25,19 @@ const WEEK = 7 * DAY;
const MONTH = 30 * DAY;
const YEAR = 365 * DAY;
const GRANULATE_UNIT_MS: Record<string, number> = {
second: SECOND,
seconds: SECOND,
minute: MINUTE,
minutes: MINUTE,
hour: HOUR,
hours: HOUR,
day: DAY,
days: DAY,
week: WEEK,
weeks: WEEK,
};
type Rule = {
maxMs: number;
granulate: string;
@@ -60,3 +73,12 @@ export function getHistoryGranularity(from: string, to: string): HistoryGranular
}
);
}
/** Переводит текст грануляции API вроде "10 minutes" в миллисекунды. */
export function parseGranulateMs(granulate: string): number {
const [amountText, unit = ''] = granulate.trim().split(/\s+/);
const amount = Number(amountText);
const unitMs = GRANULATE_UNIT_MS[unit.toLowerCase()];
return Number.isFinite(amount) && unitMs ? amount * unitMs : MINUTE;
}