Created
August 21, 2013 09:14
-
-
Save neilb/6292159 to your computer and use it in GitHub Desktop.
The script I use to fix up the date format in Changes files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# | |
# fix-changes-dates | |
# | |
# This is the script I use to fix up dates in Changes files | |
# | |
use strict; | |
use warnings; | |
my %month = | |
( | |
Jan => '01', January => '01', | |
Feb => '02', February => '02', | |
Mar => '03', March => '03', | |
Apr => '04', April => '04', | |
May => '05', | |
Jun => '06', June => '06', | |
Jul => '07', July => '07', | |
Aug => '08', August => '08', | |
Sep => '09', September => '09', | |
Oct => '10', October => '10', | |
Nov => '11', November => '11', | |
Dec => '12', December => '12', | |
); | |
my $month_re = join('|', keys %month); | |
my @days_of_the_week = qw(Mon Tue Wed Thu Fri Sat Sun); | |
my $dotw_re = join('|', @days_of_the_week); | |
while (<>) { | |
# 1.1119 (02.04.2012) | |
if (/^(\d\S+) \((\d\d)\.(\d\d)\.(\d\d\d\d)\)(.*)/) { | |
print "$1 $4-$2-$3 $5"; | |
next; | |
} | |
if (/^(\d\S+)\s+($dotw_re)\s+($month_re)\s*(\d+)\s+(\d\d:\d\d:\d\d)\s+(CET|EST|CEST)\s+(\d\d\d\d)/) { | |
my $version = $1; | |
my $month = $month{$3}; | |
my $day = $4; | |
my $time = $5; | |
my $year = $7; | |
my $tz = $6; | |
print "$version $year-$month-$day $time $tz\n"; | |
next; | |
} | |
# 1.123 Wed February 12 10:07:47 2012 | |
if (/^(\d\S+)\s+($dotw_re)\s+($month_re)\s+(\d+)\s+(\d\d:\d\d:\d\d)\s+(\d\d\d\d)/) { | |
printf "$1 $6-%s-%.2d $5\n", $month{$3}, $4; | |
next; | |
} | |
# 1.01 12 Jun 2013 | |
if (/^(\d\S+)\s+(\d+)\s+($month_re)\s+(\d\d\d\d)/) { | |
printf "$1 $4-%s-%.2d\n", $month{$3}, $2; | |
next; | |
} | |
# 0.01 Feb 2, 2013 | |
if (/^(\d\S+)\s+($month_re)\s+(\d{1,2}),\s+(\d\d\d\d)/) { | |
printf "$1 $4-%s-%.2d\n", $month{$2}, $3; | |
next; | |
} | |
# 0.011 16/2/2013 | |
# trouble with this one is US vs UK date formats | |
if (m!^(\d\S+)\s+(\d{1,2})/(\d{1,2})/(\d\d\d\d)\s*(.*)$!) { | |
my ($version, $day, $month, $year) = ($1, $2, $3, $4); | |
$day =~ s/^0//; | |
$month =~ s/^0//; | |
printf "$version $year-%.2d-%.2d\n", $month, $day; | |
next; | |
} | |
# 1.49 Tue 8 Mar 2011 | |
if (/^(\d\S+)\s+($dotw_re)\s+(\d+)\s+($month_re)\s+(\d\d\d\d)/) { | |
printf "$1 $5-%s-%.2d\n", $month{$4}, $3; | |
next; | |
} | |
print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment