All my plugins in the released stable versions, so the repository starts
[matthijs/upstream/blosxom-plugins.git] / xtaran / date_rfc822
1 # Blosxom Plugin: date_rfc822
2 # Author(s): Axel Beckert <abe@deuxchevaux.org>, based on 822-date
3 # Version: 1.0
4 # Documentation: See the bottom of this file or type: perldoc date_rfc822
5
6 package date_rfc822;
7
8 $date; # use as $date_rfc822::date
9
10 use POSIX qw(strftime);
11
12 sub start {
13   1;
14 }
15
16 sub date {
17   my ($pkg, $path, $date_ref, $mtime, @date_bits) = @_;
18
19 @localtm = localtime ($mtime);
20 $localtms = localtime ($mtime);
21 @gmttm = gmtime ($mtime);
22 $gmttms = gmtime ($mtime);
23
24 if ($localtm[0] != $gmttm[0]) {
25     die (sprintf ("local timezone differs from GMT by a non-minute interval\n"
26                  . "local time: %s\n"
27                  . "GMT time: %s\n", $localtms, $gmttms));
28 }
29
30 $localmin = $localtm[1] + $localtm[2] * 60;
31 $gmtmin = $gmttm[1] + $gmttm[2] * 60;
32
33 if ((($gmttm[6] + 1) % 7) == $localtm[6]) {
34     $localmin += 1440;
35 } elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) {
36     $localmin -= 1440;
37 } elsif ($gmttm[6] == $localtm[6]) {
38     1;
39 } else {
40     die ("822-date: local time offset greater than or equal to 24 hours\n");
41 }
42
43 $offset = $localmin - $gmtmin;
44 $offhour = $offset / 60;
45 $offmin = abs ($offset % 60);
46
47 if (abs ($offhour) >= 24) { 
48     die ("822-date: local time offset greater than or equal to 24 hours\n");
49 }
50
51 $date = sprintf 
52     (
53      "%s, %2d %s %d %02d:%02d:%02d %s%02d%02d",
54      (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$localtm[6]], # day of week
55      $localtm[3],               # day of month
56      (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$localtm[4]], # month
57      $localtm[5]+1900,          # year
58      $localtm[2],               # hour
59      $localtm[1],               # minute
60      $localtm[0],               # sec
61      ($offset >= 0) ? '+' : '-',# TZ offset direction
62      abs ($offhour),            # TZ offset hour
63      $offmin,                   # TZ offset minute
64      ) || die "822-date: output error: $!\n";
65
66
67   1;
68 }
69
70 1;
71
72 __END__
73
74 =head1 NAME
75
76 Blosxom Plug-in: date_rfc822