Skip to content

fix: correct date format for DAU calculation in StatsResources worker#11870

Open
yogeshwaran-c wants to merge 1 commit intoappwrite:1.9.xfrom
yogeshwaran-c:fix/stats-resources-dau-date-format
Open

fix: correct date format for DAU calculation in StatsResources worker#11870
yogeshwaran-c wants to merge 1 commit intoappwrite:1.9.xfrom
yogeshwaran-c:fix/stats-resources-dau-date-format

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

The DAU (Daily Active Users) threshold in the StatsResources worker uses the PHP date format string 'Y-m-d h:m:00', which contains two incorrect format specifiers:

  • h produces 12-hour time (01–12) instead of 24-hour time. For example, 14:00 becomes 02 instead of 14.
  • m produces the month number (01–12) where minutes should be. For example, at 14:30 in April, the minutes position outputs 04 (the month) instead of 30 (the actual minutes).

Combined, this means at 14:30 on April 12 the computed threshold becomes 2026-04-11 02:04:00 instead of the intended 2026-04-11 14:30:00. This causes the DAU count query to use an incorrect time boundary, producing inaccurate active user metrics.

The neighboring MAU and WAU calculations use 'Y-m-d 00:00:00' (zeroed time), so they are not affected. Only the DAU path, which needs hour-and-minute precision, has this bug.

What is the new behavior?

Changed the format string to 'Y-m-d H:i:00':

  • H — 24-hour format hours (00–23)
  • i — minutes (00–59)

This matches PHP's DateTime::format() specification and produces the correct threshold for the DAU query.

Additional context

Single-line change in src/Appwrite/Platform/Workers/StatsResources.php line 124.

The DAU (Daily Active Users) threshold was using format 'Y-m-d h:m:00'
which has two bugs: 'h' gives 12-hour time instead of 24-hour (should
be 'H'), and 'm' gives month number instead of minutes (should be 'i').

This caused the DAU query to use an incorrect threshold, producing
inaccurate active user counts.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 12, 2026

Greptile Summary

This PR fixes a bug in StatsResources.php where the DAU threshold was computed using 'Y-m-d h:m:00' — a format string with two incorrect specifiers (h for 12-hour clock and m for month instead of minutes). The corrected format 'Y-m-d H:i:00' uses the right PHP specifiers (H for 24-hour, i for minutes), producing an accurate 24-hour lookback boundary for the active-user count query.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and directly addresses the documented bug with no side effects.

The change is a one-line correction of two wrong PHP date format specifiers. The fix matches PHP's DateTime::format() spec exactly, the surrounding MAU/WAU calculations are untouched, and there are no logic, security, or style issues introduced.

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Workers/StatsResources.php Single-line fix: corrects PHP date format from 'Y-m-d h:m:00' to 'Y-m-d H:i:00' for accurate DAU threshold calculation

Reviews (1): Last reviewed commit: "fix: correct date format for DAU calcula..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant