]> dxcluster.org Git - spider.git/commitdiff
make just the time the default.
authorminima <minima>
Sat, 21 Jan 2006 00:37:12 +0000 (00:37 +0000)
committerminima <minima>
Sat, 21 Jan 2006 00:37:12 +0000 (00:37 +0000)
Fix IsoTime so it can handle it.

perl/DXXml.pm
perl/IsoTime.pm

index c40e3be041ff91c9f468dae81eae238e63b38aba..9d0a59698170c153a5db6ec4ab77ac124012c878 100644 (file)
@@ -190,7 +190,7 @@ sub toxml
 
        unless (exists $self->{'-xml'}) {
                $self->{o} ||= $main::mycall;
-               $self->{t} ||= IsoTime::dayminsec();
+               $self->{t} ||= IsoTime::hourminsec();
                $self->{id} ||= nextid();
                
                my ($name) = (ref $self) =~ /::(\w+)$/;
index 422f99123d350c8ec559346d680ed1432ea6d117..0bcf7995a8b43b16acea58debac6b4ffab68524b 100644 (file)
@@ -43,6 +43,17 @@ sub daymin
        return sprintf "%02dT%02d%02d", $day, $hour, $min; 
 }
 
+sub hourmin
+{
+       return sprintf "%02d%02d", $hour, $min; 
+
+}
+
+sub hourminsec
+{
+       return sprintf "%02d%02d%02d", $hour, $min, $sec; 
+}
+
 sub update
 {
        my $t = shift || time;
@@ -54,9 +65,23 @@ sub update
 sub unixtime
 {
        my $iso = shift;
-       
-       # get the correct month and year if it is a short date
-       if (my ($d) = $iso =~ /^(\d\d)T\d\d\d\d/) {
+
+       # get the correct day, if required
+       if (my ($h) = $iso =~ /^([012]\d)[0-5]\d(?:[0-5]\d)?$/) {
+               my ($d, $m, $y) = ($day, $month, $year);
+               if ($h != $hour) {
+                       if ($hour < 12 && $h - $hour >= 12) {
+                               # yesterday
+                               ($d, $m, $y) = _yesterday($d, $m, $y);
+                       } elsif ($hour >= 12 && $hour - $h > 12) {
+                               # tomorrow
+                               ($d, $m, $y) = _tomorrow($d, $m, $y);
+                       }
+               }
+               $iso = sprintf("%04d%02d%02dT", $y, $m, $d) . $iso;
+       } elsif (my ($d) = $iso =~ /^(\d\d)T\d\d\d\d/) {
+
+               # get the correct month and year if it is a short date
                if ($d == $day) {
                        $iso = sprintf("%04d%02d", $year, $month) . $iso;
                } else {
@@ -83,7 +108,46 @@ sub unixtime
                        }
                        $iso = sprintf("%04d%02d", $y, $m) . $iso;
                }
-       }
+       } 
+               
        return str2time($iso);
 }
+
+sub _tomorrow
+{
+       my ($d, $m, $y) = @_;
+
+       $d++;
+       my $days = _isleap($y) ? $ldays[$month-1] : $days[$month-1];
+       if ($d > $days) {
+               $d = 1;
+               $m++;
+               if ($m > 12) {
+                       $m = 1;
+                       $y++;
+               } else {
+                       $y = $year;
+               }
+       }
+
+       return ($d, $m, $y);
+}
+
+sub _yesterday
+{
+       my ($d, $m, $y) = @_;
+
+       $d--;
+       if ($d <= 0) {
+               $m--;
+               $y = $year;
+               if ($m <= 0) {
+                       $m = 12;
+                       $y--;
+               }
+               $d = _isleap($y) ? $ldays[$m-1] : $days[$m-1];
+       }
+
+       return ($d, $m, $y);
+}
 1;