fix(reporting): render "Last Seen" column in site timezone - #3268
Open
faisalahammad wants to merge 2 commits into
Open
fix(reporting): render "Last Seen" column in site timezone#3268faisalahammad wants to merge 2 commits into
faisalahammad wants to merge 2 commits into
Conversation
Event dates are stored as UTC in the events table, but the students reporting table parsed them as local time before formatting, so the "Last Seen" column always displayed UTC regardless of the WordPress timezone setting. Parse the stored event date explicitly as UTC and format it with wp_date() so the displayed date honors the site timezone. The user meta fallback (last login) was already stored in site time and keeps working as before. Fixes gocodebox#1738
The test expected 'Y-m-d' but the production code renders with
get_option('date_format'). WP default is 'F j, Y', so the CI matrix
fed a mismatch and the assertion failed across all PHP versions.
Refs gocodebox#3268
Contributor
Author
CI Fix Summary — 1 failure resolved
Tests: ✅ targeted PHPUnit passes · ✅ PHPCS clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The "Last Seen" column on the students reporting screen displayed the stored UTC value regardless of the site timezone setting. Event dates are stored as UTC in the
wp_lifterlms_eventstable (when events exist) or as site-local time in thellms_last_loginuser meta (fallback). The reporting table parsed the event date as a local wall-clock time and ran it throughdate_i18n, which produces a UTC display for that path regardless of the site offset. Sites at non-zero UTC offsets saw the wrong date.Fixes #1738
How has this been tested?
test_get_data_last_seen_respects_site_timezoneintests/phpunit/unit-tests/tables/class-llms-test-table-students.php. The test stores an event at2024-06-15 12:00:00 UTCdirectly in the events table and asserts the rendered "Last Seen" string matches the expected site-local date forgmt_offsetvalues of12,-12, and0.composer check-cspasses on all modified files.TESTING_INSTRUCTIONS.mdfor the reviewer.Screenshots
https://screendrop-worker.faisalahammad24.workers.dev/c916acc8
Types of changes
Checklist:
.changelogs/fix-1738-last-seen-utc.yml).composer tests-install).composer check-csclean; new test uses@since [version]per docs/documentation-standards.md).Changes
includes/admin/reporting/tables/llms.table.students.phpBefore:
After:
Why:
date_i18ninterprets numeric timestamps under WordPress' timezone API in a way that, for raw UTC strings from MySQL, produces a UTC display. Parsing the event date explicitly as UTC and rendering withwp_date()produces a true site-local date. The user-meta fallback path is unchanged because those values were already stored in site time.