2 # Utility routines for handling Iso 8601 date time groups
6 # Copyright (c) Dirk Koopman, G1TLH
15 use vars qw($VERSION $BRANCH $year $month $day $hour $min $sec @days @ldays);
16 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
17 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
18 $main::build += $VERSION;
19 $main::branch += $BRANCH;
21 @days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
22 @ldays = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
28 return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0;
33 return sprintf "%04d%02d%02dT%02d%02d%02d", $year, $month, $day, $hour, $min, $sec;
38 return sprintf "%02dT%02d%02d%02d", $day, $hour, $min, $sec;
43 return sprintf "%02dT%02d%02d", $day, $hour, $min;
48 my $t = shift || time;
49 ($sec,$min,$hour,$day,$month,$year) = gmtime($t);
58 # get the correct month and year if it is a short date
59 if (my ($d) = $iso =~ /^(\d\d)T\d\d\d\d/) {
61 $iso = sprintf("%04d%02d", $year, $month) . $iso;
63 my $days = _isleap($year) ? $ldays[$month-1] : $days[$month-1];
64 my ($y, $m) = ($year, $month);
66 if ($day - $d > $days / 2) {
75 if ($d - $day > $days / 2) {
84 $iso = sprintf("%04d%02d", $y, $m) . $iso;
87 return str2time($iso);