-
Notifications
You must be signed in to change notification settings - Fork 210
HPPS migration: started_at timezone conversion inflates days-to-complete calculations #7924
Description
Summary
The HPPS data migration converts the start comment meta value using convert_to_utc(), but the source value is already in local time (matching comment_date). The conversion adds the GMT offset instead of subtracting it, pushing started_at into the future relative to the UTC-based completed_at. This inflates DATEDIFF calculations for Days to Completion in Reports.
Root cause
In Student_Progress_Migration::prepare_lesson_progress_rows():
completed_at←comment_date_gmt(already UTC)started_at←convert_to_utc(meta['start'])— butstartis stored in local time (same timezone ascomment_date), so the conversion shifts it in the wrong direction
Example (site with gmt_offset = 6)
| Comments (local time) | Tables (after migration) | |
|---|---|---|
| start | 2022-05-23 22:47:51 | 2022-05-24 03:47:51 (+5h shift) |
| complete | 2022-05-23 22:47:51 | 2022-05-23 16:47:51 (UTC) |
| DATEDIFF + 1 | 1 day | 2 days (crosses midnight) |
The start meta value 2022-05-23 22:47:51 is local time. convert_to_utc() treats it as local and adds +6h → 2022-05-24 04:47:51. Meanwhile completed_at is comment_date_gmt = 2022-05-23 16:47:51 (UTC). The resulting started_at is 11 hours after completed_at.
Impact
- Days to Completion values on the Reports > Lessons page are inflated when using tables-based storage
- The magnitude depends on the site's GMT offset — larger offsets cause more dates to cross midnight boundaries
- Comments-based storage is unaffected (both
comment_dateandstartmeta are in local time)
Possible fix
The start meta value should be treated the same way as comment_date — either:
- Don't convert it (store as-is, since
comment_dateis stored ascreated_atwithout conversion), or - Subtract the offset instead of adding it (convert local → UTC correctly)
Option 1 would also require removing CONVERT_TZ from the tables-based queries that compare started_at and completed_at, since they'd be in different timezones. Option 2 is cleaner but requires a data migration for existing sites.
Steps to reproduce
- Set up a site with
gmt_offset> 0 - Create a course with a lesson and quiz
- Have students complete the lesson
- Enable HPPS and run the migration
- Compare Reports > Lessons "Days to Completion" between comments-based and tables-based storage