refactor: replace moment.js with luxon and remove the bundled library#4937
Draft
SteveGilvarry wants to merge 1 commit into
Draft
refactor: replace moment.js with luxon and remove the bundled library#4937SteveGilvarry wants to merge 1 commit into
SteveGilvarry wants to merge 1 commit into
Conversation
luxon is already bundled and loaded globally, so the remaining moment.js
usages are migrated to it and the library is removed.
- skin.js convertLabelFormat: map strftime tokens to luxon format tokens
(YYYY->yyyy, DD->dd, A->a, ...) and emit the %N monitor name as a luxon
literal (each char single-quoted, '' for an apostrophe) so token
characters and apostrophes in names survive.
- skin.js addVideoTimingTrack: parse StartDateTime with
DateTime.fromSQL (ISO fallback) and advance with the immutable
plus({seconds:1}); drop the dead commented WebVTT block that also used
moment.
- montagereview.js secs2inputstr/secs2dbstr: DateTime.fromMillis().toFormat();
filter normalisation: fromISO with fromSQL fallback.
- report_event_audit.js: parse min/max inputs via a tolerant
fromISO/fromSQL helper and compare luxon DateTimes.
- functions.php: drop the moment.min.js script tag.
- remove web/skins/classic/js/moment.js, moment.min.js, moment.js.URL.
Chart.js (report.php) only uses its category axis, not the moment-backed
time scale, so it is unaffected. Resolves the moment.js CodeQL alert.
Parity verified in node: luxon output is byte-identical to moment for the
epoch/format, parse and label-format conversions (incl. apostrophe names).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
luxon is already bundled and loaded globally (
functions.php), so the remainingmoment.jscall sites are migrated to it and the library is removed (moment.js,moment.min.js,moment.js.URL, and the<script>include). Resolves the moment.js CodeQL alert.Changes
skin.jsconvertLabelFormat— strftime tokens now map to luxon tokens (YYYY→yyyy,DD→dd,A→a,DDDD→ooo, …). The%Nmonitor name is emitted as a luxon literal (each char single-quoted,''for an apostrophe) so token characters and apostrophes in names survive.skin.jsaddVideoTimingTrack— parsesStartDateTimewithDateTime.fromSQL(ISO fallback) and advances via the immutableplus({seconds:1}). Removed the dead commented WebVTT block that also used moment.montagereview.js—secs2inputstr/secs2dbstruseDateTime.fromMillis().toFormat(); filter date normalisation usesfromISOwith afromSQLfallback.report_event_audit.js— min/max inputs parsed via a tolerantfromISO/fromSQLhelper and compared as luxon DateTimes.Chart.js (
report.php) only uses its category axis, not the moment-backedtimescale, so it is unaffected.Verification done
eslintclean on all three JS files;php -lclean;node --checkclean.YYYY-MM-DD HH:mm:ssparse, and label-format conversion across representative formats — including the apostrophe-name edge case (which caught and fixed a%Nescaping bug).Manual testing checklist (each impacted area)
%p, weekday%a,%Nname) and for a monitor whose name contains an apostrophe.secs2inputstr/secs2dbstr), and applying a date/time filter builds the correct API URL (YYYY-MM-DD HH:mm:ss).moment is not defined.