gulp-util.date creates timezone‑dependent timestamps that vary across build agents
0 reputation · 02 Aug 2025, 11:10 UTC
0 reputation · 02 Aug 2025, 11:10 UTC
When a gulp task uses gulp-util.date to generate timestamps for file names or log entries, the output reflects the local timezone of the machine running the task. This causes the same task to produce different strings on build agents located in different regions, which can break reproducible builds and complicate cache‑based workflows. The gulp team has not decided whether gulp-util.date should be altered to return UTC‑based strings, leaving the behavior as an open design choice.
Given that gulp-util is deprecated and future releases may drop the helper, developers need to know whether they should rely on UTC formatting libraries now or wait for a potential change in gulp‑util.
31775 reputation · 02 Aug 2025, 18:01 UTC
Should gulp-util.date be changed to always return UTC timestamps?
No. The Gulp team has not committed to modifying gulp‑util.date, and the package is marked deprecated. There is no official plan to make it UTC‑based or to provide a replacement helper.
If not, what is the recommended approach for obtaining consistent timestamps in gulp tasks today?
Use a UTC‑based formatter that does not depend on the host’s time zone. The simplest and most future‑proof method is to replace every call to gulp-util.date() with new Date().toISOString(). If you need a custom format, use a lightweight library that explicitly works in UTC, e.g. dayjs().utc().format('YYYYMMDDHHmmssZ') or moment.utc().format().
gulpfile.js replace const now = gulputil.date(); with const now = new Date().toISOString();.
const now = new Date().toISOString().replace(/[-:T]/g, '').replace('Z', ''); gives a compact UTC string without colons.
npm i dayjs utc and then
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
dayjs.extend(utc);
const now = dayjs().utc().format('YYYYMMDDHHmmss');
TZ=UTC or TZ=America/New_York on two machines and run the task. new Date().toISOString() will always output the same string.
Does the gulp project plan to provide an official UTC‑based date helper as a replacement?
No public roadmap indicates such a feature. The gulp‑util repository shows no recent commits and a deprecation notice, suggesting the package will be removed in a future major release. Until an official helper appears, the safest path is to use Node’s built‑in UTC formatting or a dedicated UTC library.
gulpfile.js for any gulp-util.date() usage.
new Date().toISOString() or a UTC‑aware library call.
TZ settings to confirm determinism.
Build agents in different regions will produce different strings if they use gulp-util.date(). That breaks cache keys, file naming conventions, and any downstream logic that assumes a stable timestamp. Using a UTC‑based formatter removes this source of nondeterminism.
When you run your tests, check the TZ environment variable on each agent. If you see different timestamp outputs, you’re still using a local‑time helper. Setting TZ=UTC globally for the build job guarantees that new Date().toISOString() will always produce the same result, even if the underlying system time zone differs.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.