WS-NA: Temporal Migration (PR 3: Update formatDuration to use Temporal) - #14233
Draft
Isabella-Mitchell wants to merge 28 commits into
Draft
WS-NA: Temporal Migration (PR 3: Update formatDuration to use Temporal)#14233Isabella-Mitchell wants to merge 28 commits into
Isabella-Mitchell wants to merge 28 commits into
Conversation
…-temporal-migrate-duration
…-temporal-migrate-duration
…mporal is not present.
…-temporal-migrate-duration
Base automatically changed from
WS-NA-temporal-migrate-add-internal-adapter
to
latest
August 28, 2026 10:29
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates legacy duration formatting from Moment.js to Temporal while preserving locale-aware output.
Changes:
- Adds Temporal/Intl duration and locale helpers with tests.
- Loads the Temporal polyfill globally for Next.js, Jest, and Storybook.
- Updates duration-formatting documentation and removes redundant imports.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
ws-nextjs-app/setupTests.ts |
Loads Temporal for Next.js tests. |
ws-nextjs-app/pages/[service]/watch/[id]/[live]/LiveTvPageLayout.tsx |
Removes the local polyfill import. |
ws-nextjs-app/pages/_app.page.tsx |
Loads Temporal application-wide. |
src/testHelpers/jest-setup.js |
Loads Temporal for Jest. |
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/temporalHelpers/index.ts |
Adds Temporal formatting helpers. |
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/temporalHelpers/index.test.ts |
Tests the new helpers. |
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/index.ts |
Migrates formatDuration to Temporal. |
src/app/legacy/psammead/psammead-timestamp-container/README.md |
Documents the migrated API. |
src/app/components-webcore/SportDataHeader/head-to-head-v2/tests/helpers/index.test.ts |
Removes a redundant test import. |
.storybook/preview.tsx |
Loads Temporal in Storybook and fixes indentation. |
Suppressed comments (4)
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/temporalHelpers/index.ts:50
- The overrides are keyed by language, but this lookup uses the complete canonical locale. Consequently valid Pashto variants such as
ps-AFbypass the requiredarabextoverride even though the documented behavior applies to Pashto generally. Look up the override using the locale's language subtag.
new Intl.NumberFormat(
LOCALE_NUMBERING_SYSTEM_OVERRIDES[sanitisedLocale] ?? sanitisedLocale,
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/index.ts:62
- This derives the language from the unsanitised input, so supported forms such as
fa_af(explicitly documented above) or uppercaseARdo not receive the Arabic comma. Derive it fromsanitisedLocale, which has already normalized underscores and casing.
// Extract language code (e.g., 'fa' from 'fa-AF', 'ar' from 'ar-EG')
const langCode = locale.split('-')[0];
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/temporalHelpers/index.ts:82
DurationFormatpermits repeated tokens (for examplemm:mm), but eachreplaceonly handles the first occurrence;mm:mmtherefore becomes05:5m. Replace all occurrences so every value accepted by the public type formats correctly.
return format
.replace('h', values.h)
.replace('mm', values.mm)
.replace('ss', values.ss)
.replace('m', values.m);
src/app/legacy/psammead/psammead-timestamp-container/src/utilities/index.ts:51
- Temporal accepts signed ISO durations, but flooring negative totals creates invalid clock components:
-PT30Sproduces minutes-1and seconds-30, rendered as-01:-30. Handle the sign separately from absolute components, or explicitly reject negative durations during sanitisation.
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+13
to
+15
| const LOCALE_NUMBERING_SYSTEM_OVERRIDES: Record<string, string> = { | ||
| ps: 'ps-u-nu-arabext', | ||
| }; |
Comment on lines
+46
to
+48
| const totalSeconds = sanitiseDuration(duration).total({ | ||
| unit: 'seconds', | ||
| }); |
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.
Resolves JIRA: WS-NA - 10% time. See plan
Summary
Updates formatDuration to use Temporal. Requires global import of temporal polyfill for storybook and jest (and moved to _app out of specific components/ pages currently using it).
Note the only 'locale' related overrides we have to do are:
string.replace(/,/g, '،');in src/app/legacy/psammead/psammead-locales/moment)src/app/legacy/psammead/psammead-locales/moment/ps.js)Therefore, this is the easiest function in src/app/legacy/psammead/psammead-timestamp-container/src/utilities/index.ts to update to Temporal
Code changes
Testing
Useful Links