Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

856 B
Raw Blame
import { propertyDateSortKey } from '@property/utils/sort';

/** Match the server's half-open ranges; absent or invalid dates use the missing bucket. */
export function propertyDateGroupKey(
  value: string | Date | null | undefined,
  bucketing: {
    ranges: readonly {
      key: string;
      start?: string | null;
      end?: string | null;
    }[];
    missingValueBucketKey: string;
  }
): string {
  const timestamp = propertyDateSortKey(value);
  if (timestamp === undefined) return bucketing.missingValueBucketKey;
  const date = timestamp;
  const range = bucketing.ranges.find(
    (range) =>
      (range.start == null ||
        date >= (propertyDateSortKey(range.start) ?? Infinity)) &&
      (range.end == null ||
        date < (propertyDateSortKey(range.end) ?? -Infinity))
  );
  return range?.key ?? bucketing.missingValueBucketKey;
}