[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm
raeburn
raeburn at source.lon-capa.org
Thu Sep 22 08:48:40 EDT 2011
raeburn Thu Sep 22 12:48:40 2011 EDT
Modified files:
/loncom/interface lonnavmaps.pm
Log:
- timeToHumanString() displays time more intelligently when called
to support <displayduedate> with format attrib set.
- If delta is > 24 hours, format is ignored if only H:M:S or H:M
(i.e., format is %T or %R).
- If delta is < 24 hours, seconds are included in display if format
includes them (i.e., format is %T, or contains %S).
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.463 loncom/interface/lonnavmaps.pm:1.464
--- loncom/interface/lonnavmaps.pm:1.463 Thu Sep 15 01:06:41 2011
+++ loncom/interface/lonnavmaps.pm Thu Sep 22 12:48:40 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.463 2011/09/15 01:06:41 raeburn Exp $
+# $Id: lonnavmaps.pm,v 1.464 2011/09/22 12:48:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
@@ -779,14 +779,31 @@
# Less than an hour
if ( $delta < $hour ) {
- # If so, use minutes
+ # If so, use minutes; or minutes, seconds (if format requires)
my $minutes = floor($delta / 60);
+ if (($format ne '') && ($format =~ /\%(T|S)/)) {
+ my $display;
+ if ($minutes == 1) {
+ $display = "${prefix}1 minute";
+ } else {
+ $display = "$prefix$minutes minutes";
+ }
+ my $seconds = $delta % $minute;
+ if ($seconds == 0) {
+ $display .= $tense;
+ } elsif ($seconds == 1) {
+ $display .= ", 1 second$tense";
+ } else {
+ $display .= ", $seconds seconds$tense";
+ }
+ return $display;
+ }
if ($minutes == 1) { return "${prefix}1 minute$tense"; }
return "$prefix$minutes minutes$tense";
}
# Is it less than 24 hours away? If so,
- # display hours + minutes
+ # display hours + minutes, (and + seconds, if format specified it)
if ( $delta < $hour * 24) {
my $hours = floor($delta / $hour);
my $minutes = floor(($delta % $hour) / $minute);
@@ -801,15 +818,30 @@
if ($minutes == 0) {
$minuteString = "";
}
+ if (($format ne '') && ($format =~ /\%(T|S)/)) {
+ my $display = "$prefix$hourString$minuteString";
+ my $seconds = $delta-(($hours * $hour)+($minutes * $minute));
+ if ($seconds == 0) {
+ $display .= $tense;
+ } elsif ($seconds == 1) {
+ $display .= ", 1 second$tense";
+ } else {
+ $display .= ", $seconds seconds$tense";
+ }
+ return $display;
+ }
return "$prefix$hourString$minuteString$tense";
}
+ # Date/time is more than 24 hours away
+
my $dt = DateTime->from_epoch(epoch => $time)
->set_time_zone(&Apache::lonlocal::gettimezone());
- # If there's a caller supplied format, use it.
+ # If there's a caller supplied format, use it, unless it only displays
+ # H:M:S or H:M.
- if ($format ne '') {
+ if (($format ne '') && ($format ne '%T') && ($format ne '%R')) {
my $timeStr = $dt->strftime($format);
return $timeStr.' ('.$dt->time_zone_short_name().')';
}
More information about the LON-CAPA-cvs
mailing list