groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 01/01: [gropdf] Fix date format.


From: Colin Watson
Subject: [groff] 01/01: [gropdf] Fix date format.
Date: Tue, 30 Apr 2024 07:13:43 -0400 (EDT)

cjwatson pushed a commit to branch master
in repository groff.

commit 0815e503dba8d5c05921d68c6c718fe8f8440ee8
Author: Colin Watson <cjwatson@debian.org>
AuthorDate: Tue Apr 30 12:06:31 2024 +0100

    [gropdf] Fix date format.
    
    Commit d7bbfb04ea25a82a8597cdef6ebb391cb78ab47c caused gropdf to emit
    invalid PDF dates: the minutes field should not have a leading sign
    character, and the sign character before the hours field should be "Z"
    if local time is equal to Universal Time.
    
    Thanks to Christof Meerwald for the report and the patch.
    
    * src/devices/gropdf/gropdf.pl: Call PDFDate with the output of `time`
      rather than one of the processed versions.
      (PDFDate): Accept an epoch-seconds argument rather than a reference to
      a list as returned by `gmtime` or `localtime`.  Calculate the
      relationship between local time and UT more carefully.  Remove
      incorrect sign character before minutes field.
---
 src/devices/gropdf/gropdf.pl | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index acf86389f..1656db821 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -592,13 +592,7 @@ for $papersz ( split(" ", lc($possiblesizes).' #duff#') )
     # If we get here, $papersz was invalid, so try the next one.
 }
 
-my @dt;
-if ($ENV{SOURCE_DATE_EPOCH}) {
-    @dt=gmtime($ENV{SOURCE_DATE_EPOCH});
-} else {
-    @dt=localtime;
-}
-my $dt=PDFDate(\@dt);
+my $dt=PDFDate(time);
 
 my %info=('Creator' => "(groff version $cfg{GROFF_VERSION})",
          'Producer' => "(gropdf version $cfg{GROFF_VERSION})",
@@ -1102,14 +1096,19 @@ sub GetObj
 
 sub PDFDate
 {
-    my $dt=shift;
+    my $ts=shift;
+    my @dt;
     my $offset;
+    my $rel;
     if ($ENV{SOURCE_DATE_EPOCH}) {
        $offset=0;
+       @dt=gmtime($ENV{SOURCE_DATE_EPOCH});
     } else {
-       $offset=mktime((localtime $dt)[0..5]) - mktime((gmtime $dt)[0..5]);
+       @dt=localtime($ts);
+       $offset=mktime(@dt[0..5]) - mktime((gmtime $ts)[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)));
+    $rel=($offset==0)?'Z':($offset>0)?'+':'-';
+    
return(sprintf("D:%04d%02d%02d%02d%02d%02d%s%02d'%02d'",$dt[5]+1900,$dt[4]+1,$dt[3],$dt[2],$dt[1],$dt[0],$rel,int(abs($offset)/3600),int((abs($offset)%3600)/60)));
 }
 
 sub ToPoints



reply via email to

[Prev in Thread] Current Thread [Next in Thread]