/** * How a period is cut into the buckets a trend is drawn over, and the one rule * every chart over dated rows has to obey: a bucket is drawn only when it is * COMPLETE. The bucket holding "now" is a partial period, and so is a bucket the * period's own edge cuts through; drawing either beside finished ones draws a * collapse that is not there. */ export type BucketUnit = "day" | "week" | "month"; export interface Bucket { /** Inclusive. */ start: Date; /** Exclusive. */ end: Date; /** The bucket holds "now", or runs past the period's edge — its figure is not a whole one. */ partial: boolean; } export declare const startOfDay: (date: Date) => Date; /** Whole days from `start` to `end`, both included. */ export declare function daySpan(start: Date, end: Date): number; /** The day `days` whole days after `start`, counting `start` as the first. */ export declare function dayAfter(start: Date, days: number): Date; /** The unit a span is read in — a month by day, half a year by week, longer by month. */ export declare function bucketUnit(start: Date, end: Date): BucketUnit; /** * The buckets of `[start, end]`, aligned to the unit's own boundaries so a week * is a calendar week and a month a calendar month. A bucket is partial when it * holds `now` or when the period's edge cuts through it; a bucket that starts * after `now` is not returned at all. */ export declare function bucketsOf(start: Date, end: Date, now: Date, unit?: BucketUnit): Bucket[]; /** The dates a stored value parses to — `YYYY-MM-DD`, with or without a time. */ export declare function parseWhen(value: string | null | undefined): Date | null; /** Each bucket's sum of `value` over the rows whose `when` falls in it. */ export declare function sumByBucket(rows: readonly T[], when: (row: T) => string | null | undefined, value: (row: T) => number | null | undefined, buckets: readonly Bucket[]): number[]; /** Whether a stored date falls inside `[start, end]` — both ends inclusive, whole days. */ export declare function inPeriod(value: string | null | undefined, start: Date, end: Date): boolean; /** The percentage change from `previous` to `current`; `null` when the base is zero. */ export declare function percentChange(current: number, previous: number): number | null;