[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm /localize lonlocal.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Thu, 18 Oct 2007 21:08:31 -0000


albertel		Thu Oct 18 17:08:31 2007 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
    /loncom/localize	lonlocal.pm 
  Log:
  - add ability to set the timezone of a course
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.402 loncom/interface/lonnavmaps.pm:1.403
--- loncom/interface/lonnavmaps.pm:1.402	Fri Oct  5 14:48:20 2007
+++ loncom/interface/lonnavmaps.pm	Thu Oct 18 17:08:08 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.402 2007/10/05 18:48:20 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.403 2007/10/18 21:08:08 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,9 +36,9 @@
 use Apache::lonlocal;
 use Apache::lonnet;
 use POSIX qw (floor strftime);
-use Data::Dumper; # for debugging, not always 
 use Time::HiRes qw( gettimeofday tv_interval );
 use LONCAPA;
+use DateTime();
 
 # symbolic constants
 sub SYMB { return 1; }
@@ -305,9 +305,6 @@
     } 
     my $now = time();
 
-    my @time = localtime($time);
-    my @now = localtime($now);
-
     # Positive = future
     my $delta = $time - $now;
 
@@ -366,22 +363,25 @@
             return "$prefix$hourString$minuteString$tense";
         }
 
+	my $dt = DateTime->from_epoch(epoch => $time)
+	                 ->set_time_zone(&Apache::lonlocal::gettimezone());
+
 	# If there's a caller supplied format, use it.
 
-	if($format ne '') {
-	    my $timeStr = strftime($format, localtime($time));
-	    return $timeStr.&Apache::lonlocal::gettimezone($time);
+	if ($format ne '') {
+	    my $timeStr = $dt->strftime($format);
+	    return $timeStr.' ('.$dt->time_zone_short_name().')';
 	}
 
         # Less than 5 days away, display day of the week and
         # HH:MM
 
         if ( $delta < $day * 5 ) {
-            my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time));
+            my $timeStr = $dt->strftime("%A, %b %e at %I:%M %P (%Z)");
             $timeStr =~ s/12:00 am/00:00/;
             $timeStr =~ s/12:00 pm/noon/;
             return ($inPast ? "last " : "this ") .
-                $timeStr.&Apache::lonlocal::gettimezone($time);
+                $timeStr;
         }
         
 	my $conjunction='on';
@@ -391,19 +391,22 @@
 	    $conjunction='by';
 	}
         # Is it this year?
-        if ( $time[5] == $now[5]) {
+	my $dt_now = DateTime->from_epoch(epoch => $now)
+	                     ->set_time_zone(&Apache::lonlocal::gettimezone());
+        if ( $dt->year() == $dt_now->year()) {
             # Return on Month Day, HH:MM meridian
-            my $timeStr = strftime("$conjunction %A, %b %e at %I:%M %P", localtime($time));
+            my $timeStr = $dt->strftime("$conjunction %A, %b %e at %I:%M %P (%Z)");
             $timeStr =~ s/12:00 am/00:00/;
             $timeStr =~ s/12:00 pm/noon/;
-            return $timeStr.&Apache::lonlocal::gettimezone($time);
+            return $timeStr;
         }
 
         # Not this year, so show the year
-        my $timeStr = strftime("$conjunction %A, %b %e %Y at %I:%M %P", localtime($time));
+        my $timeStr = 
+	    $dt->strftime("$conjunction %A, %b %e %Y at %I:%M %P (%Z)");
         $timeStr =~ s/12:00 am/00:00/;
         $timeStr =~ s/12:00 pm/noon/;
-        return $timeStr.&Apache::lonlocal::gettimezone($time);
+        return $timeStr;
     }
 }
 
@@ -1045,7 +1048,6 @@
      );
 my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR);
 
-use Data::Dumper;
 sub render_parts_summary_status {
     my ($resource, $part, $params) = @_;
     if (!$resource->is_problem() && !$resource->contains_problem) { return '<td></td>'; }
@@ -1289,7 +1291,6 @@
     # Print key?
     if ($printKey) {
         $result .= '<table border="0" cellpadding="2" cellspacing="0">';
-        my $date=localtime;
         $result.='<tr><td align="right" valign="bottom">Key:&nbsp;&nbsp;</td>';
 	my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
         if ($navmap->{LAST_CHECK}) {
Index: loncom/localize/lonlocal.pm
diff -u loncom/localize/lonlocal.pm:1.41 loncom/localize/lonlocal.pm:1.42
--- loncom/localize/lonlocal.pm:1.41	Mon Aug 28 10:26:25 2006
+++ loncom/localize/lonlocal.pm	Thu Oct 18 17:08:31 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Localization routines
 #
-# $Id: lonlocal.pm,v 1.41 2006/08/28 14:26:25 albertel Exp $
+# $Id: lonlocal.pm,v 1.42 2007/10/18 21:08:31 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -164,6 +164,7 @@
 use Apache::localize;
 use locale;
 use POSIX qw(locale_h strftime);
+use DateTime();
 
 require Exporter;
 
@@ -259,7 +260,10 @@
 # ========================================================== Localize localtime
 sub gettimezone {
     my ($time) = @_;
-    return ' ('.&strftime("%Z",localtime($time)).')';
+    if ($Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.timezone'}) {
+	return $Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.timezone'};
+    }
+    return 'local';
 }
 
 sub locallocaltime {
@@ -267,16 +271,26 @@
     if (!defined($thistime) || $thistime eq '') {
 	return &mt('Never');
     }
+
+    my $dt = DateTime->from_epoch(epoch => $thistime)
+                     ->set_time_zone(&gettimezone());
     if ((&current_language=~/^en/) || (!$lh)) {
-	return ''.localtime($thistime).&gettimezone($thistime);
+
+	return $dt->strftime("%a %b %e %I:%M:%S %P %Y (%Z)");
     } else {
 	my $format=$lh->maketext('date_locale');
 	if ($format eq 'date_locale') {
-	    return ''.localtime($thistime);
+	    return $dt->strftime("%a %b %e %I:%M:%S %P %Y (%Z)");
 	}
-	my ($seconds,$minutes,$twentyfour,$day,$mon,$year,$wday,$yday,$isdst)=
-	    localtime($thistime);
-	my $month=(split(/\,/,$lh->maketext('date_months')))[$mon];
+	my $time_zone  = $dt->time_zone_short_name();
+	my $seconds    = $dt->second();
+	my $minutes    = $dt->minute();
+	my $twentyfour = $dt->hour();
+	my $day        = $dt->day_of_month();
+	my $mon        = $dt->month()-1;
+	my $year       = $dt->year();
+	my $wday       = $dt->wday()-1;
+	my $month  =(split(/\,/,$lh->maketext('date_months')))[$mon];
 	my $weekday=(split(/\,/,$lh->maketext('date_days')))[$wday];
 	if ($seconds<10) {
 	    $seconds='0'.$seconds;
@@ -284,7 +298,6 @@
 	if ($minutes<10) {
 	    $minutes='0'.$minutes;
 	}
-	$year+=1900;
 	my $twelve=$twentyfour;
 	my $ampm;
 	if ($twelve>12) {
@@ -293,12 +306,11 @@
 	} else {
 	    $ampm=$lh->maketext('date_am');
 	}
-	foreach 
-	('seconds','minutes','twentyfour','twelve','day','year',
-	 'month','weekday','ampm') {
+	foreach ('seconds','minutes','twentyfour','twelve','day','year',
+		 'month','weekday','ampm') {
 	    $format=~s/\$$_/eval('$'.$_)/gse;
 	}
-	return $format.&gettimezone($thistime);
+	return $format." ($time_zone)";
     }
 }