benvinegar / counterscale

Scalable web analytics you run yourself on Cloudflare
https://counterscale.dev
MIT License
1.3k stars 52 forks source link

Daily chart doesn't navigate daylight savings time changes correctly / extra x-axis data points #61

Closed benvinegar closed 5 months ago

benvinegar commented 5 months ago

Note this doesn't affect overall counts, the tables, etc. This is strictly just the daily chart visualization.

Basically, CF Analytics Engine will adjust the result set based on whether DST is in effect – below the America/Toronto timezone returns 05:00 for "midnight" until 03-11, after which DST kicks in, and midnight is now 04:00 in UTC.

[
  {
    count: '38',
    _bucket: '2024-03-09 00:00:00',
    bucket: '2024-03-09 05:00:00'
  },
  {
    count: '46',
    _bucket: '2024-03-10 00:00:00',
    bucket: '2024-03-10 05:00:00'
  },
  {
    count: '30',
    _bucket: '2024-03-11 00:00:00',
    bucket: '2024-03-11 04:00:00' /* <-- DST starts */
  },
  {
    count: '29',
    _bucket: '2024-03-12 00:00:00',
    bucket: '2024-03-12 04:00:00'
  },

This result set is fine, but since it's merged with a JavaScript-calculated result set (where the math does not account for DST) to produce buckets where there is no data (CF will not return a row if count is 0), you get this mangled object with some DST-aware data points and some not.