From: Dirk Eddelbuettel <edd@debian.org>
Date: Oct, 27 2026 16:29:04 -0500
Subject: [PATCH] <short summary of the patch>

This patch switches from the previoisly used 'PKG_BUILT_STAMP' to the more
common / recent SOURCE_DATE_EPOCH.

As the former was formatted timestamp (taken from the debian/changelog) and
the latter is the seconds since epoch, the parsing step needed in tools/R/admin.R
is reverted to a formatting step; similarly in basepkg.mk an (ISO8601-formatted) 
string is created (portably via awk).

--- r-base-4.6.1.orig/share/make/basepkg.mk
+++ r-base-4.6.1/share/make/basepkg.mk
@@ -85,8 +85,8 @@ mkRbase:
 
 mkdesc:
 	@if test -f DESCRIPTION; then \
-	  if test "$(PKG_BUILT_STAMP)" != ""; then \
-	    $(ECHO) "tools:::.install_package_description('.', '$(top_builddir)/library/${pkg}', '$(PKG_BUILT_STAMP)')" | \
+	  if test "$(SOURCE_DATE_EPOCH)" != ""; then \
+	    $(ECHO) "tools:::.install_package_description('.', '$(top_builddir)/library/${pkg}', '$(SOURCE_DATE_EPOCH)')" | \
 	    R_DEFAULT_PACKAGES=NULL $(R_EXE) > /dev/null ; \
 	  else \
 	  $(ECHO) "tools:::.install_package_description('.', '$(top_builddir)/library/${pkg}')" | \
@@ -97,8 +97,9 @@ mkdesc:
 ## for base and tools
 mkdesc2:
 	@$(INSTALL_DATA) DESCRIPTION $(top_builddir)/library/$(pkg)
-	@if test "$(PKG_BUILT_STAMP)" != ""; then \
-	  $(ECHO) "Built: R $(VERSION); ; $(PKG_BUILT_STAMP); $(R_OSTYPE)" \
+	@if test "$(SOURCE_DATE_EPOCH)" != ""; then \
+	  $(ECHO) "Built: R $(VERSION); ; \
+	     `echo ${SOURCE_DATE_EPOCH} | awk '{print strftime("%a %b %d %H:%M:%S %p %Z %Y",$$1, 1)}'`; $(R_OSTYPE)" \
 	     >> $(top_builddir)/library/$(pkg)/DESCRIPTION ; \
 	else \
 	  $(ECHO) "Built: R $(VERSION); ; `TZ=UTC date`; $(R_OSTYPE)" \
--- r-base-4.6.1.orig/src/library/tools/R/admin.R
+++ r-base-4.6.1/src/library/tools/R/admin.R
@@ -66,10 +66,11 @@ function(dir, outDir, builtStamp=charact
         builtStamp <- format(Sys.time(), "%Y-%m-%d %H:%M:%S",
                              tz = "UTC", usetz = TRUE)
     } else {
-        ## Debian may have passed a timestamp in RFC 2822/5322 format,
-        ## if it parses use it but as ISO 8601, UTC, no sub-seconds
+        ## Reproducible Builds (by Debian and others) may set a 'SOURCE_DATE_EPOCH'
+        ## environment variable which basepkg.mk passes here as character; we format
+        ## it as ISO 8601, UTC, no subseconds
         prev <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
-        if (!is.na(res <- strptime(builtStamp, "%a, %d %b %Y %T %z", tz="UTC")))
+        if (!is.na(res <- as.POSIXct(as.numeric(builtStamp), tz="UTC")))
             builtStamp <- format(res, "%Y-%m-%d %H:%M:%S",
                                  tz = "UTC", usetz = TRUE)
         Sys.setlocale("LC_TIME", prev)
