Skip to content

HPPS migration: started_at timezone conversion inflates days-to-complete calculations #7924

@donnapep

Description

@donnapep

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_atcomment_date_gmt (already UTC)
  • started_atconvert_to_utc(meta['start']) — but start is stored in local time (same timezone as comment_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_date and start meta are in local time)

Possible fix

The start meta value should be treated the same way as comment_date — either:

  1. Don't convert it (store as-is, since comment_date is stored as created_at without conversion), or
  2. 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

  1. Set up a site with gmt_offset > 0
  2. Create a course with a lesson and quiz
  3. Have students complete the lesson
  4. Enable HPPS and run the migration
  5. Compare Reports > Lessons "Days to Completion" between comments-based and tables-based storage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions