retitle 782294 please make the output reproducible
tags 782294 + fixed-upstream
thanks

> asciidoc: make timestamps reproducible adding the flag
> --use-utc-timezone

Renaming bug - upstream have merged a (superior) SOURCE_DATE_EPOCH-based
patch instead.

Also attaching updated patch to match.


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
--- asciidoc-8.6.9.orig/asciidoc.py
+++ asciidoc-8.6.9/asciidoc.py
@@ -1268,25 +1268,27 @@ def char_encode(s):
     else:
         return s
 
-def time_str(t):
-    """Convert seconds since the Epoch to formatted local time string."""
-    t = time.localtime(t)
-    s = time.strftime('%H:%M:%S',t)
-    if time.daylight and t.tm_isdst == 1:
-        result = s + ' ' + time.tzname[1]
+def date_time_str(t):
+    """Convert seconds since the Epoch to formatted local date and time strings."""
+    source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
+    if source_date_epoch is not None:
+        t = time.gmtime(min(t, int(source_date_epoch)))
     else:
-        result = s + ' ' + time.tzname[0]
+        t = time.localtime(t)
+    date_str = time.strftime('%Y-%m-%d',t)
+    time_str = time.strftime('%H:%M:%S',t)
+    if source_date_epoch is not None:
+        time_str += ' UTC'
+    elif time.daylight and t.tm_isdst == 1:
+        time_str += ' ' + time.tzname[1]
+    else:
+        time_str += ' ' + time.tzname[0]
     # Attempt to convert the localtime to the output encoding.
     try:
-        result = char_encode(result.decode(locale.getdefaultlocale()[1]))
+        time_str = char_encode(time_str.decode(locale.getdefaultlocale()[1]))
     except Exception:
         pass
-    return result
-
-def date_str(t):
-    """Convert seconds since the Epoch to formatted local date string."""
-    t = time.localtime(t)
-    return time.strftime('%Y-%m-%d',t)
+    return date_str, time_str
 
 
 class Lex:
@@ -1453,8 +1455,7 @@ class Document(object):
         Set implicit attributes and attributes in 'attrs'.
         """
         t = time.time()
-        self.attributes['localtime'] = time_str(t)
-        self.attributes['localdate'] = date_str(t)
+        self.attributes['localdate'], self.attributes['localtime'] = date_time_str(t)
         self.attributes['asciidoc-version'] = VERSION
         self.attributes['asciidoc-file'] = APP_FILE
         self.attributes['asciidoc-dir'] = APP_DIR
@@ -1484,8 +1485,7 @@ class Document(object):
             else:
                 t = None
             if t:
-                self.attributes['doctime'] = time_str(t)
-                self.attributes['docdate'] = date_str(t)
+                self.attributes['docdate'], self.attributes['doctime'] = date_time_str(t)
             if self.infile != '<stdin>':
                 self.attributes['infile'] = self.infile
                 self.attributes['indir'] = os.path.dirname(self.infile)
--- asciidoc-8.6.9.orig/doc/asciidoc.1.txt
+++ asciidoc-8.6.9/doc/asciidoc.1.txt
@@ -162,6 +162,18 @@ The plugin commands perform as follows:
   names starting with a period are skipped.
 
 
+ENVIRONMENT VARIABLES
+---------------------
+
+*`SOURCE_DATE_EPOCH`*::
+  If the `SOURCE_DATE_EPOCH` environment variable is set to a UNIX
+  timestamp, then the `{docdate}`, `{doctime}`, `{localdate}`, and
+  `{localtime}` attributes are computed in the UTC time zone, with any
+  timestamps newer than `SOURCE_DATE_EPOCH` replaced by
+  `SOURCE_DATE_EPOCH`. (This helps software using AsciiDoc to build
+  reproducibly.)
+
+
 EXAMPLES
 --------
 `asciidoc asciidoc_file_name.txt`::
--- asciidoc-8.6.9.orig/doc/asciidoc.txt
+++ asciidoc-8.6.9/doc/asciidoc.txt
@@ -4603,11 +4603,11 @@ predefined intrinsic attributes:
   {basebackend}         html or docbook
   {blockname}           current block name (note 8).
   {brvbar}              broken vertical bar (|) character
-  {docdate}             document last modified date
+  {docdate}             document last modified date (note 9)
   {docdir}              document input directory name  (note 5)
   {docfile}             document file name  (note 5)
   {docname}             document file name without extension (note 6)
-  {doctime}             document last modified time
+  {doctime}             document last modified time (note 9)
   {doctitle}            document title (from document header)
   {doctype-<doctype>}   empty string ''
   {doctype}             document type specified by `-d` option
@@ -4625,8 +4625,8 @@ predefined intrinsic attributes:
   {ldquo}               Left double quote character (note 7)
   {level}               title level 1..4 (in section titles)
   {listindex}           the list index (1..) of the most recent list item
-  {localdate}           the current date
-  {localtime}           the current time
+  {localdate}           the current date (note 9)
+  {localtime}           the current time (note 9)
   {lsquo}               Left single quote character (note 7)
   {lt}                  less than (<) character entity
   {manname}             manpage name (defined in NAME section)
@@ -4697,6 +4697,13 @@ predefined intrinsic attributes:
    glossary
 
    tables:: table
+9. If the `SOURCE_DATE_EPOCH` environment variable is set to a UNIX
+   timestamp, then the `{docdate}`, `{doctime}`, `{localdate}`, and
+   `{localtime}` attributes are computed in the UTC time zone, with any
+   timestamps newer than `SOURCE_DATE_EPOCH` replaced by
+   `SOURCE_DATE_EPOCH`. (This helps software using AsciiDoc to build
+   reproducibly.)
+
 
 ======
 

Reply via email to