Browse Source

Dpkg::Changelog::Entry::Debian: Use Time::Piece instead of Date::Parse

The new module is in the perl core distribution, which reduces the build
and run-time dependencies, helping with architecture bootstrapping.

Prompted-by: Helmut Grohne <helmut@subdivi.de>
Guillem Jover 9 years ago
parent
commit
7a71b4b78e

+ 0 - 1
README

@@ -76,7 +76,6 @@ To enable optional functionality or programs, this software might be needed:
 
 To run the test suite («make check»):
 
-  TimeDate perl module
   IO-String perl module
   Test::Pod perl module (optional)
   Test::Strict perl module (optional)

+ 3 - 0
debian/changelog

@@ -5,6 +5,9 @@ dpkg (1.18.2) UNRELEASED; urgency=low
   * Perl modules:
     - Remove non-functional timezone name support from
       Dpkg::Changelog::Entry::Debian.
+    - Use Time::Piece (part of the perl core distribution) instead of
+      Date::Parse in Dpkg::Changelog::Entry::Debian. This reduces the build
+      and run-time dependencies, and helps architecture bootstrapping.
   * Documentation:
     - Fix grammar in dpkg-architecture(1).
       Thanks to Chris Lamb <lamby@debian.org>. Closes: #787616

+ 2 - 2
debian/control

@@ -15,7 +15,7 @@ Build-Depends: debhelper (>= 9), pkg-config, flex,
  libselinux1-dev (>= 1.28-4) [linux-any],
  libkvm-dev [kfreebsd-any],
  libncursesw5-dev,
- libtimedate-perl, libio-string-perl
+ libio-string-perl
 
 Package: libdpkg-dev
 Section: libdevel
@@ -68,7 +68,7 @@ Section: perl
 Priority: optional
 Architecture: all
 Multi-Arch: foreign
-Depends: dpkg (>= 1.16.3), perl, libtimedate-perl, ${misc:Depends}
+Depends: dpkg (>= 1.16.3), perl, ${misc:Depends}
 Recommends: libfile-fcntllock-perl, bzip2, xz-utils
 Suggests: debian-keyring, gnupg | gnupg2, gpgv | gpgv2,
  gcc | c-compiler, binutils, patch

+ 8 - 2
scripts/Dpkg/Changelog/Entry/Debian.pm

@@ -29,7 +29,7 @@ our @EXPORT_OK = qw(
 );
 
 use Exporter qw(import);
-use Date::Parse;
+use Time::Piece;
 
 use Dpkg::Gettext;
 use Dpkg::Control::Fields;
@@ -164,7 +164,13 @@ sub check_trailer {
 	if ($3 ne '  ') {
 	    push @errors, g_('badly formatted trailer line');
 	}
-	unless (defined str2time($4)) {
+
+	my $fmt = '';
+	$fmt .= '%a, ' if defined $5;
+	$fmt .= '%d %b %Y %T %z';
+
+	local $ENV{LC_ALL} = 'C';
+	unless (defined Time::Piece->strptime($4, $fmt)) {
 	    push @errors, sprintf(g_("couldn't parse date %s"), $4);
 	}
     } else {

+ 10 - 2
scripts/t/Dpkg_Changelog.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 84;
+use Test::More tests => 92;
 
 use File::Basename;
 
@@ -36,7 +36,7 @@ my $vendor = get_current_vendor();
 #########################
 
 foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
-    "$datadir/regressions") {
+    "$datadir/regressions", "$datadir/date-format") {
 
     my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
     $changes->load($file);
@@ -288,6 +288,14 @@ Xb-Userfield2: foobar
 ', 'change items 2');
 	is($items[5], "  * Update S-V.\n", 'change items 3');
     }
+    if ($file eq "$datadir/date-format") {
+        is($data[0]->get_timestamp(), '01 Jul 2100 23:59:59 -1200',
+           'get date w/o DoW, and negative timezone offset');
+        is($data[1]->get_timestamp(), 'Tue, 27 Feb 2050 12:00:00 +1245',
+           'get date w/ DoW, and positive timezone offset');
+        is($data[2]->get_timestamp(), 'Mon, 01 Jan 2000 00:00:00 +0000',
+           'get date w/ DoW, and zero timezone offset');
+    }
     if ($file eq "$datadir/regressions") {
 	my $f = $changes->dpkg();
 	is("$f->{Version}", '0', 'version 0 correctly parsed');

+ 17 - 0
scripts/t/Dpkg_Changelog/date-format

@@ -0,0 +1,17 @@
+date-format (0.2) unstable; urgency=low
+
+  * Date without day of week name and negative timezone offset.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org>  01 Jul 2100 23:59:59 -1200
+
+date-format (0.1) unstable; urgency=low
+
+  * Date with day of week name and positive timezone offset.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org>  Tue, 27 Feb 2050 12:00:00 +1245
+
+date-format (0.0) unstable; urgency=low
+
+  * Date with day of week name and zero timezone offset.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org>  Mon, 01 Jan 2000 00:00:00 +0000