ChemPal Documentation - v1.6.0
    Preparing search index...
    • Formats a date as the YYYY-MM-DD key used by the stats store, in the viewer's local time. These buckets are user-facing — "today" and the daily chart's axis have to mean the user's day, not UTC's — so the store keys off this too, keeping recording and filtering on the same calendar.

      Parameters

      • date: Date

        The date to format.

      Returns string

      The local date key.

      // In UTC-5, 23:30 local on the 18th is 04:30 UTC on the 19th:
      toDateKey(new Date("2026-07-19T04:30:00Z")); // => "2026-07-18"
      export function toDateKey(date: Date): string {
      const month = `${date.getMonth() + 1}`.padStart(2, '0');
      const day = `${date.getDate()}`.padStart(2, '0');
      return `${date.getFullYear()}-${month}-${day}`;
      }