commit-womb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commit-womb] gnumaint gnufsd-psql


From: Kaloian Doganov
Subject: [commit-womb] gnumaint gnufsd-psql
Date: Thu, 26 Feb 2009 12:40:14 +0000

CVSROOT:        /sources/womb
Module name:    gnumaint
Changes by:     Kaloian Doganov <kaloian>       09/02/26 12:40:14

Modified files:
        .              : gnufsd-psql 

Log message:
        Use Date::Calc for date/time calculations.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnumaint/gnufsd-psql?cvsroot=womb&r1=1.1&r2=1.2

Patches:
Index: gnufsd-psql
===================================================================
RCS file: /sources/womb/gnumaint/gnufsd-psql,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gnufsd-psql 24 Feb 2009 09:56:46 -0000      1.1
+++ gnufsd-psql 26 Feb 2009 12:40:12 -0000      1.2
@@ -1,15 +1,15 @@
 #!/usr/bin/env perl
-# $Id: gnufsd-psql,v 1.1 2009/02/24 09:56:46 kaloian Exp $
+# $Id: gnufsd-psql,v 1.2 2009/02/26 12:40:12 kaloian Exp $
 # Extract information about GNU packages from the Free Software
 # Directory's PostgreSQL database.
 #
 # Dependencies:
-#   perl (5.8.x), libdbd-pg-perl
+#   perl (5.8.x), libdbd-pg-perl, libdate-calc-perl
 
 use warnings;
 use strict;
 use DBI;
-use Time::Local;
+use Date::Calc qw ( check_date Delta_Days Add_Delta_YMD Today );
 
 # Configuration:
 # ==============================
@@ -19,14 +19,14 @@
 my $password = "";
 
 # `activity-status' calculation:
-my $activity_interval = 365 * 24 * 60 * 60; # ~ one year (in secs)
-my $activity_reference = time(); # now
+my @activity_interval = (-1, 0, 0); # One year ago (Y, M, D)
+my @activity_reference = Today ();
 #===============================
 
-# FIXME: What about handling UTF-8 from PostgreSQL?
+my @activity_threshold = Add_Delta_YMD (@activity_reference,
+                                       @activity_interval);
 
-# FIXME: Use Date::Calc instead of manual Unix time calculations
-#        (libdate-calc-perl is already installed on fencepost).
+# FIXME: What about handling UTF-8 from PostgreSQL?
 
 my ($dbh, $sth_homepage, $sth_download_url, $sth_activity_status);
 
@@ -177,14 +177,13 @@
   return $url;
 }
 
-# Converts SQL ISO date format (YYYY-MM-DD) to Unix time.
-sub iso_date_to_unix($)
+# Converts SQL ISO date format (YYYY-MM-DD) to Date::Calc YMD.
+sub iso_date_to_ymd($)
 {
   my ($iso_date) = @_;
   my ($year, $month, $day) = split (/-/, $iso_date);
-  $month--;
-  $year -= 1900;
-  my $unix = timegm (0, 0, 0, $day, $month, $year);
+  my @ymd = ($year, $month, $day);
+  return @ymd;
 }
 
 # Fetch activity-status for a project.
@@ -198,11 +197,15 @@
   return "stale" if ! $row;
 
   my $status = "stale";
+  my $comments = "";
   if ($row->{"date"}) {        
-    my $release = iso_date_to_unix ($row->{"date"});
-    my $now = gmtime ();
-    my $threshold = $activity_reference - $activity_interval;
-    $status = "ok" if $release > $threshold;
+    my @release = iso_date_to_ymd ($row->{"date"});
+    if (check_date (@release)) {
+      $status = "ok" if Delta_Days (@activity_threshold, @release) >= 0;
+    }
+    else {
+      $comments .= " Invalid release date: $row->{date}.";
+    }
   }
 
   my $date = $row->{"date"};
@@ -217,7 +220,9 @@
     $number = "";
   }
 
-  return "$status $date$number";
+  my $result = "$status $date$number";
+  $result .= " #" . $comments if $comments;
+  return $result;
 }
 
 # Dump a project to STDOUT.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]