[adding Deri to CC]

At 2023-07-09T13:24:27+0100, Colin Watson wrote:
> On Sun, Jul 09, 2023 at 02:42:55AM +0100, Colin Watson wrote:
> > So, how about the attached patch?
> 
> I somehow neglected to update doc/groff.texi.  Here's an updated
> version.

I have no objection to this patch.  I think Colin is right that none
but reproducible-build mavens are going to use $SOURCE_DATE_EPOCH.

I am curious to see some concrete examples of the sorts of shenanigans
TZ is used for in reproducible build testing, which foreclose the groff
1.23.0 approach as far as Debian (and presumably others) are concerned.

Also, we should solicit a +1 from Deri for the gropdf patch.  I'm
attaching just that part for his convenience.

Regards,
Branden
* src/devices/gropdf/gropdf.pl: If SOURCE_DATE_EPOCH is set, return the
  overridden time after passing it through `gmtime`.  Otherwise, pass
  the current time through `localtime`.
  (PDFDate): Fix output in the case where the local offset from UTC is
  not a whole number of hours.  (Previously, the minutes offset field
  was always set to zero.)

---
 src/devices/gropdf/gropdf.1.man   | 10 +++++-----
 src/devices/gropdf/gropdf.pl      | 16 ++++++++++++++--

diff --git a/src/devices/gropdf/gropdf.1.man b/src/devices/gropdf/gropdf.1.man
index d1d39bbe0..20a957e68 100644
--- a/src/devices/gropdf/gropdf.1.man
+++ b/src/devices/gropdf/gropdf.1.man
@@ -1673,18 +1673,18 @@ A timestamp
 to use as the output creation timestamp in place of the current time.
 .
 The time is converted to human-readable form using Perl's
-.I \%localtime()
+.I \%gmtime()
 function and recorded in a PDF comment.
 .
 .
 .TP
 .I TZ
-The time zone to use when converting the current time
-(or value of
-.IR SOURCE_DATE_EPOCH )
-to human-readable form;
+The time zone to use when converting the current time to human-readable form;
 see
 .MR tzset 3 .
+If
+.I SOURCE_DATE_EPOCH
+is used, it is always converted to human-readable form using UTC.
 .
 .
 .\" ====================================================================
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index c65a1051f..0e1b612a5 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -23,6 +23,7 @@
 use strict;
 use warnings;
 use Getopt::Long qw(:config bundling);
+use POSIX qw(mktime);
 
 use constant
 {
@@ -343,7 +344,12 @@ for $papersz ( split(" ", lc($possiblesizes).' #duff#') )
     # If we get here, $papersz was invalid, so try the next one.
 }
 
-my (@dt)=localtime($ENV{SOURCE_DATE_EPOCH} || time);
+my @dt;
+if ($ENV{SOURCE_DATE_EPOCH}) {
+    @dt=gmtime($ENV{SOURCE_DATE_EPOCH});
+} else {
+    @dt=localtime;
+}
 my $dt=PDFDate(\@dt);
 
 my %info=('Creator' => "(groff version $cfg{GROFF_VERSION})",
@@ -628,7 +634,13 @@ sub GetObj
 sub PDFDate
 {
     my $dt=shift;
-    return(sprintf("D:%04d%02d%02d%02d%02d%02d%+03d'00'",$dt->[5]+1900,$dt->[4]+1,$dt->[3],$dt->[2],$dt->[1],$dt->[0],( localtime time() + 3600*( 12 - (gmtime)[2] ) )[2] - 12));
+    my $offset;
+    if ($ENV{SOURCE_DATE_EPOCH}) {
+	$offset=0;
+    } else {
+	$offset=mktime((localtime $dt)[0..5]) - mktime((gmtime $dt)[0..5]);
+    }
+    return(sprintf("D:%04d%02d%02d%02d%02d%02d%+03d'%+03d'",$dt->[5]+1900,$dt->[4]+1,$dt->[3],$dt->[2],$dt->[1],$dt->[0],int($offset/3600),int(($offset%3600)/60)));
 }
 
 sub ToPoints

Attachment: signature.asc
Description: PGP signature

Reply via email to