Skip to content

lib: add internal Temporal utils#63312

Open
Renegade334 wants to merge 1 commit into
nodejs:mainfrom
Renegade334:temporal-utils
Open

lib: add internal Temporal utils#63312
Renegade334 wants to merge 1 commit into
nodejs:mainfrom
Renegade334:temporal-utils

Conversation

@Renegade334
Copy link
Copy Markdown
Member

@Renegade334 Renegade334 commented May 14, 2026

Spun out from #63154 to garner comments. See that PR for an example of how this might be used in practice, and #60789 for an example of a feature that could make use of it.

Integrating Temporal into Node.js APIs is currently made challenging by the fact that it is not available at bootstrapping, meaning no primordials and no user-resistant way of accessing the Temporal globals. Unlike other similar features like SharedArrayBuffer, Temporal is very commonly polyfilled across the ecosystem, so running into a non-builtin implementation in the global namespace is a real possibility.

The likelihood is that the combination of build-time and run-time flags that govern this behaviour is not going away any time soon, so in the meantime, we could really do with something more robust than seeking a property on globalThis and hoping for the best.

This introduces a internal/util/temporal module which is initialized during the pre-execution phase, to mitigate against the user mutability issue. The module exports a number of utilities:

  • a boolean hasTemporal property for determining whether Node.js is running with builtin Temporal support
  • type-check methods (isTemporalDuration(), isTemporalInstant() etc.) which perform realm-agnostic type checking for Temporal builtin objects, available regardless of whether Temporal support is enabled
  • if Temporal is available, provides primordial-ish access to the Temporal constructors and salient static/instance methods

Obviously this isn't snapshottable, so unlike primordials, there is a small per-run overhead here. Worthwhile?

@Renegade334 Renegade334 added the discuss Issues opened for discussions and feedbacks. label May 14, 2026
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. util Issues and PRs related to the built-in util module. labels May 14, 2026
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 98.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.05%. Comparing base (c24e552) to head (907a6eb).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/util/temporal.js 97.95% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #63312    +/-   ##
========================================
  Coverage   90.05%   90.05%            
========================================
  Files         714      715     +1     
  Lines      225247   225438   +191     
  Branches    42578    42616    +38     
========================================
+ Hits       202842   203019   +177     
- Misses      14181    14195    +14     
  Partials     8224     8224            
Files with missing lines Coverage Δ
lib/internal/process/pre_execution.js 98.26% <100.00%> (-0.12%) ⬇️
lib/internal/util/temporal.js 97.95% <97.95%> (ø)

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discuss Issues opened for discussions and feedbacks. needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants