"Previous period" with "Match day of week" picks the later weekday, so the comparison overlaps the selected range
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia con shift_to_nearest/3 in lib/plausible/stats/comparisons.ex e leggi i casi esistenti di corrispondenza del giorno della settimana in test/plausible/stats/comparisons_test.exs. Il report identifica le differenze di data con segno come causa e suggerisce di confrontare le distanze assolute. Aggiungi un caso di test in cui il giorno della settimana corrispondente precedente sia più vicino, poi esegui i test di comparisons; il lavoro è concluso quando l'intervallo di confronto resta prima del periodo selezionato e i casi esistenti continuano a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Watch in BugReels (the date menu opens at 0:04, Compare is clicked at 0:13, and every top stat shows "24 Sep - 5 Oct" under "1 Oct - 12 Oct" from 0:13)
Past Issues Searched
- I have searched open and closed issues to make sure that the bug has not yet been reported
Issue is a Bug Report
- This is a bug report and not a feature request, nor asking for self-hosted support
Using official Plausible Cloud hosting or self-hosting?
Plausible Cloud from plausible.io
Describe the bug
With Compare set to "Previous period" and "Match day of week" (the default), the comparison range is moved to the next matching weekday even when the previous one is closer. When the period length leaves a remainder of 4 to 6 days after dividing by 7, the comparison moves forward by 4 to 6 days and overlaps the selected range.
Reproduced on the public demo dashboard https://plausible.io/plausible.io on 2026-10-26. The code is the same on master (57f734e).
Steps:
- Open https://plausible.io/plausible.io?period=custom&from=2026-10-01&to=2026-10-12 (Thu 1 Oct to Mon 12 Oct).
- Open the date menu and click "Compare". Leave "Previous period" and "Match day of week" as they are.
- Read the date lines under the top stats.
Actual: every top stat compares "1 Oct - 12 Oct" with "24 Sep - 5 Oct", so 1 to 5 Oct is counted in both periods. The query API returns the same range:
POST /api/stats/plausible.io/query
{"date_range":["2026-10-01","2026-10-12"],"metrics":["visitors"],"include":{"compare":"previous_period","compare_match_day_of_week":true}}
-> "comparison_date_range":["2026-09-24T00:00:00+00:00","2026-10-05T23:59:59+00:00"]
Built-in periods hit it on some days. On 2026-10-26, "Month to Date" compares 1 Oct - 26 Oct with 10 Sep - 5 Oct, and "Year to Date" compares 1 Jan - 26 Oct with 13 Mar 2025 - 5 Jan 2026. The dashboard also sends compare: previous_period with compare_match_day_of_week: true for the top stats when Compare is off, so the percent change arrows use this range too. In the recording, Unique visitors shows "309k" and "25%" before Compare is turned on, which is 309k against the 247k of 24 Sep - 5 Oct.
Expected behavior
The unshifted previous period is Sat 19 Sep - Wed 30 Sep. The nearest Thursday to 19 Sep is 17 Sep (2 days back, against 5 days forward), so the comparison should be 17 Sep - 28 Sep. The docs describe Previous period as "the period immediately before your selected date range". With the same rule, Month to Date on 2026-10-26 would compare with 3 Sep - 28 Sep and Year to Date with 6 Mar 2025 - 29 Dec 2025.
Cause
shift_to_nearest/3 sorts the two candidate dates by the signed Date.diff:
Date.diff(date, next) is always negative and Date.diff(date, previous) is always positive, so the next occurrence always sorts first. For 19 Sep and a Thursday target it compares -5 (24 Sep) with 2 (17 Sep) and picks 24 Sep. This sort has been there since #2822, which introduced the feature to shift the comparison "to start on the same day of the week as the source query".
Sorting by abs(Date.diff(date, &1)) would pick the nearest day. I checked this in a Python model of previous_period, year_over_year and shift_to_nearest, not by running the Elixir test suite. The model reproduces the current ranges above, gives the expected ranges with the change, and gives unchanged results for the match-day-of-week cases in test/plausible/stats/comparisons_test.exs (March 2023 with the rejected start date, February 2023, January 2023, and year over year to 1 March 2023). Those tests only cover cases where the later weekday is also the nearest one.
Screenshots
The replay link above shows the dashboard.
Environment
- OS: Linux
- Browser: Chrome
- Browser Version: 151
This report was drafted with Claude Code (Claude Opus 5.5). The bug was reproduced on the demo, and the cause was checked against the linked source and a Python model of the function.
- Lingua principale
- Elixir
- Stelle
- 29.7k
- Fork
- 1.9k
- Merge medio
- 3g 22h
- PR unite (30g)
- 50
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di plausible/analytics
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
-
ObanErrorReporter purges imported data when the cleanup worker crashes — silent loss of completed CSV importsForse già presa @EmmS21 l’ha presa 95 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
plausible/analytics#5201 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Wrong API URL for GTMAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
plausible/analytics#5200 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
[Tracker] Scroll-depth tracking still forces layout on large pages after #6174Forse già presa @trotzig l’ha presa 20 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 18/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di plausible/analytics
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
taskforcesh/bullmq#5038 ·
I maintainer di solito rispondono entro 1 giorno
-
L: python L: ruby:bundler T: bug 🐞
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
dependabot/dependabot-core#16756 ·
I maintainer di solito rispondono entro 1 giorno
-
feat: signup pageApertad: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 85/100