From: Dirk Eddelbuettel <edd@debian.org>
Date: Oct, 14 2026 21:00:00 -0500
Subject: [PATCH] Make build/install-stage \Sexpr timestamps deterministic

The 'build' and 'install' stage \Sexpr macros on the Rd2HTML man page call
format(Sys.time()), which is evaluated while the internal help database is built
(stages "build" and "install") and bakes the wall-clock time into
tools/help/tools.rdb (and hence .rdx).  Prefer the value of SOURCE_DATE_EPOCH
when set (as done by e.g. Debian), falling back to Sys.time() otherwise so
upstream behaviour is preserved when it is not set.  The 'render' stage is
evaluated only when the page is rendered, so it is left untouched.

--- r-base-4.6.1.orig/src/library/tools/man/Rd2HTML.Rd
+++ r-base-4.6.1/src/library/tools/man/Rd2HTML.Rd
@@ -171,11 +171,11 @@ Rd2ex(Rd, out = "", defines = .Platform$OS.type,
   For example, this man page was:
   \enumerate{
     \item built on
-    \Sexpr[stage=build]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")},
+    \Sexpr[stage=build]{format(as.POSIXct(if (nzchar(t <- Sys.getenv("SOURCE_DATE_EPOCH"))) as.numeric(t) else Sys.time(), origin = "1970-01-01", tz = "UTC"), "\%Y-\%m-\%d at \%H:\%M:\%S")},
     \item installed on
-    \Sexpr[stage=install]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}, and
+    \Sexpr[stage=install]{format(as.POSIXct(if (nzchar(t <- Sys.getenv("SOURCE_DATE_EPOCH"))) as.numeric(t) else Sys.time(), origin = "1970-01-01", tz = "UTC"), "\%Y-\%m-\%d at \%H:\%M:\%S")}, and
     \item rendered on
-    \Sexpr[stage=render]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}.
+    \Sexpr[stage=render]{format(as.POSIXct(if (nzchar(t <- Sys.getenv("SOURCE_DATE_EPOCH"))) as.numeric(t) else Sys.time(), origin = "1970-01-01", tz = "UTC"), "\%Y-\%m-\%d at \%H:\%M:\%S")}.
   }
 }
 
