Shlomi Fish avatar Shlomi Fish committed 9e92cb4

Add more formats to the upgrade to CPAN Changes script.

Comments (0)

Files changed (1)

shlomif-settings/home-bin-executables/bin/upgrade-to-CPAN-Changes

 use strict;
 use warnings;
 
+use List::Util qw(first);
+
 use DateTime::Format::Strptime;
 
-my $strp = DateTime::Format::Strptime->new(
-    pattern   => '%a %d %b %T %Y',
+my @strp_s = (map {
+    DateTime::Format::Strptime->new(
+    pattern   => $_,
     locale    => 'en_US',
     time_zone => 'Asia/Jerusalem',
+    )
+    }
+    (
+        '%b %d, %Y',
+        '%Y-%m-%d',
+        '%a %b %d %T %Y',
+        '%a %d %b %T %Y',
+    )
 );
 
-my $strp_us = DateTime::Format::Strptime->new(
-    pattern   => '%a %b %d %T %Y',
-    locale    => 'en_US',
-    time_zone => 'Asia/Jerusalem',
-);
-
-while (my $l = <ARGV>)
+while (my $l = <STDIN>)
 {
     chomp($l);
-    if (my ($v, $space, $date_str) = $l =~ m{\A(v?[\d\.]+)(\s+)(\S.*)\z}ms)
+    if (my ($v, $space, $date_str) = $l =~ m{\A(v?[\d\.]+)(\s+)(?:-\s*)?(\S.*)\z}ms)
     {
         $date_str =~ s/\s+\b(?:IDT|IST)\b\s+/ /;
-        if (defined (my $d = $strp->parse_datetime($date_str) // $strp_us->parse_datetime($date_str)))
+        if (defined (my $d = first {defined($_) } map { $_->parse_datetime($date_str) } @strp_s))
         {
-            print $v, $space, $d->strftime("%Y-%m-%d"), "\n";
+            printf ("%-8s%s\n", $v, $d->strftime("%Y-%m-%d"));
         }
         else
         {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.