File: clweek.pl

package info (click to toggle)
chalow 1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 444 kB
  • sloc: perl: 1,534; makefile: 52
file content (34 lines) | stat: -rwxr-xr-x 1,029 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env perl
# $Id: clweek.pl,v 1.1 2003/01/18 01:53:09 yto Exp $
# usage: prog ChangeLogFileName > NewFileName
# before: 2000-06-12  YAM Tat  <yto@example.com>
# before: Mon Jun 12 08:05:49 2000  YAM Tat  <yto@example.com>
# after:  2000-06-12 (Mon)  YAM Tat  <yto@example.com>

use POSIX;
use Time::Local;
setlocale(LC_TIME, "C");

my %mon;
for ($i = 0; $i < 12; $i++) {
    $mon{('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')[$i]} = $i + 1;
}

while (<>) {
    # for  2000-06-12  YAM Tat  <yto@example.com>
    s/^(\d{4})-(\d\d)-(\d\d)\s\s/
        sprintf "%04d-%02d-%02d (%s)  ", $1, $2, $3,
	get_weekday_name($1, $2, $3)/ex;
    # for  Mon Jun 12 08:05:49 2000  YAM Tat  <yto@example.com>
    s/^([A-Z]..)\s([A-Z]..)\s+(\d+).+(\d{4})/
        sprintf "%04d-%02d-%02d (%s)", $4, $mon{$2}, $3, 
	get_weekday_name($4, $mon{$2}, $3)/ex;

    print;
}

sub get_weekday_name {
    ($y, $m, $d) = @_;
    return strftime "%a", localtime timelocal(0, 0, 0, $d, $m - 1, $y);
}