Package: doxygen
Version: 1.8.9.1-3
Followup-For: Bug #785624
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: timestamps

Ximin:
Thanks for point me to the timestamps proposal page.
I modified the patch according it.
Description: Allow set current date and time externally.
 Allow the date and time to be set externally by the environment
 variable SOURCE_DATE_EPOCH, whose expected value is a unix time.
 If the SOURCE_DATE_EPOCH value is invalid it is ignored silently.
Author: Juan Picca <jumap...@gmail.com>
Last-Update: 2015-06-29
---
--- a/src/rtfgen.cpp
+++ b/src/rtfgen.cpp
@@ -49,7 +49,7 @@
 
 static QCString dateToRTFDateString()
 {
-  const QDateTime &d = QDateTime::currentDateTime();
+  const QDateTime &d = DoxygenDateTime::get();
   QCString result;
   result.sprintf("\\yr%d\\mo%d\\dy%d\\hr%d\\min%d\\sec%d",
       d.date().year(), d.date().month(), d.date().day(),
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -18,6 +18,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <math.h>
+#include <time.h>
 
 #include "md5.h"
 
@@ -90,6 +91,38 @@
 #define REL_PATH_TO_ROOT "../../"
 
 //------------------------------------------------------------------------
+// DoxygenDateTime implementation
+//------------------------------------------------------------------------
+
+QDateTime DoxygenDateTime::current; // initialize static to null
+
+QDateTime DoxygenDateTime::get()
+{
+  if (current.isNull())
+  {
+    if (const char* source_date_epoch = getenv("SOURCE_DATE_EPOCH"))
+    {
+      // we ignore silently errors in SOURCE_DATE_EPOCH
+      errno = 0;
+      time_t tt = (time_t) strtol(source_date_epoch, NULL, 10);
+      if (errno == 0)
+      {
+        if (struct tm *tb = gmtime(&tt))
+        {
+          current = QDateTime(QDate(tb->tm_year + 1900, tb->tm_mon + 1,
+              tb->tm_mday), QTime(tb->tm_hour, tb->tm_min, tb->tm_sec));
+        }
+      }
+    }
+    if (!current.isValid())
+    {
+      current = QDateTime::currentDateTime();
+    }
+  }
+  return current;
+}
+
+//------------------------------------------------------------------------
 // TextGeneratorOLImpl implementation
 //------------------------------------------------------------------------
 
@@ -2460,7 +2493,7 @@ QCString fileToString(const char *name,b
 
 QCString dateToString(bool includeTime)
 {
-  QDateTime current = QDateTime::currentDateTime();
+  QDateTime current = DoxygenDateTime::get();
   return theTranslator->trDateTime(current.date().year(),
                                    current.date().month(),
                                    current.date().day(),
@@ -2473,7 +2506,7 @@ QCString dateToString(bool includeTime)
 
 QCString yearToString()
 {
-  const QDate &d=QDate::currentDate();
+  const QDate &d = DoxygenDateTime::get().date();
   QCString result;
   result.sprintf("%d", d.year());
   return result;
--- a/src/util.h
+++ b/src/util.h
@@ -24,6 +24,8 @@
 
 #include <qlist.h>
 #include <ctype.h>
+#include <cstdlib>
+#include <qdatetime.h>
 #include "types.h"
 #include "sortdict.h"
 #include "docparser.h"
@@ -60,6 +62,15 @@ class FTextStream;
 
 //--------------------------------------------------------------------
 
+/** Handle the doxygen date and time. */
+class DoxygenDateTime
+{
+  public:
+    static QDateTime get();
+  private:
+    static QDateTime current;
+};
+
 /** Abstract interface for a hyperlinked text fragment. */
 class TextGeneratorIntf
 {

Reply via email to