[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 08 Aug 2002 13:43:04 -0000


www		Thu Aug  8 09:43:04 2002 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  New routines to handle dates
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.50 loncom/interface/loncommon.pm:1.51
--- loncom/interface/loncommon.pm:1.50	Thu Aug  8 09:06:22 2002
+++ loncom/interface/loncommon.pm	Thu Aug  8 09:43:04 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.50 2002/08/08 13:06:22 matthew Exp $
+# $Id: loncommon.pm,v 1.51 2002/08/08 13:43:04 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -80,7 +80,7 @@
 use strict;
 use Apache::lonnet();
 use GDBM_File;
-use POSIX qw(strftime);
+use POSIX qw(strftime mktime);
 use Apache::Constants qw(:common);
 use Apache::lonmsg();
 my $readit;
@@ -1150,6 +1150,47 @@
 }
 
 ###############################################
+
+
+sub timehash {
+    my @ltime=localtime(shift);
+    return ( 'seconds' => $ltime[0],
+             'minutes' => $ltime[1],
+             'hours'   => $ltime[2],
+             'day'     => $ltime[3],
+             'month'   => $ltime[4]+1,
+             'year'    => $ltime[5]+1900,
+             'weekday' => $ltime[6],
+             'dayyear' => $ltime[7]+1,
+             'dlsav'   => $ltime[8] );
+}
+
+sub maketime {
+    my %th=@_;
+    return POSIX::mktime(
+        ($th{'seconds'},$th{'minutes'},$th{'hours'},
+         $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,$th{'dlsav'}));
+}
+
+
+sub findallcourses {
+    my %courses=();
+    my $now=time;
+    foreach (keys %ENV) {
+	if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
+	    my ($starttime,$endtime)=$ENV{$_};
+            my $active=1;
+            if ($starttime) {
+		if ($now<$starttime) { $active=0; }
+            }
+            if ($endtime) {
+                if ($now>$endtime) { $active=0; }
+            }
+            if ($active) { $courses{$1.'_'.$2}=1; }
+        }
+    }
+    return keys %courses;
+}
 
 ###############################################