TeX \time primitive: missing time zone configuration for reproducible timestamps
0 reputation · 25 Feb 2022, 10:45 UTC
0 reputation · 25 Feb 2022, 10:45 UTC
TeX's \time, \day, \month, and \year primitives report the host operating system's local clock at engine start without any time zone awareness. This behavior makes reproducible timestamps impossible when the same source is compiled on machines with different TZ settings or across daylight-saving transitions. PDF metadata fields such as \pdfcreationdate inherit the same local-time values, so cross-platform builds produce inconsistent creation dates. The engine provides no primitive to query, set, or offset the time zone, nor to convert the reported values to UTC. External wrappers or LuaTeX callbacks can adjust the environment before invocation, but the core primitives remain bound to the process-local clock.
What configuration mechanism would allow a document to declare its intended time zone so that \time and derived primitives yield consistent, zone-independent values? Can \pdfcreationdate be made to emit a fixed UTC timestamp without relying on external environment manipulation?
35275 reputation · 25 Feb 2022, 19:19 UTC
There is no built‑in mechanism in the core TeX engine to declare a time zone; the \\time, \\day, \\month, and \\year primitives are set once at startup from the C library localtime() call, which reflects the process’s local time zone.
localtime() at engine start; there is no primitive to query, set, or offset the time zone.To obtain zone‑independent values you must fix the source of time before the engine starts, e.g., by setting the TZ environment variable to UTC, or, in LuaTeX, compute UTC via os.date('!*t') and redefine the primitives with \\directlua.
TZ=UTC before running the engine:export TZ=UTC
pdflatex mydoc.tex
\\directlua{
local utc = os.date('!*t')
tex.time = utc.hour*60 + utc.min
tex.day = utc.day
tex.month = utc.month
tex.year = utc.year
}
This forces the primitives to return UTC values for the rest of the run.
Without touching the environment, define a fixed timestamp string and assign it to the PDF Info dictionary:
\\def\\mycreationdate{D:20261012074125Z}
\\pdfinfo{/CreationDate (\\mycreationdate)}
This works with pdfTeX, XeTeX, or LuaTeX; engines lacking \\pdfinfo (plain TeX) cannot modify the creation date.
Check that \\time changes when TZ is toggled:
tex -halt-on-error '\\showthe\\time'
TZ=UTC tex -halt-on-error '\\showthe\\time'
Inspect the PDF’s Info field with pdfinfo or pdftk to confirm the CreationDate matches the supplied string.
Diagnostic note: Are you using pdfTeX, XeTeX, or LuaTeX? The manual \\pdfcreationdate override relies on the \\pdfinfo primitive, which is unavailable in plain TeX builds.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.