[LON-CAPA-cvs] cvs: loncom(version_2_7_X) /interface loncommon.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 19 Sep 2008 23:09:30 -0000
raeburn Fri Sep 19 19:09:30 2008 EDT
Modified files: (Branch: version_2_7_X)
/loncom/interface loncommon.pm
Log:
Backport changes to &timehash() and &maketime() included in 1.687.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.679.2.4 loncom/interface/loncommon.pm:1.679.2.5
--- loncom/interface/loncommon.pm:1.679.2.4 Fri Sep 19 19:03:20 2008
+++ loncom/interface/loncommon.pm Fri Sep 19 19:09:29 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.679.2.4 2008/09/19 23:03:20 raeburn Exp $
+# $Id: loncommon.pm,v 1.679.2.5 2008/09/19 23:09:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3353,16 +3353,21 @@
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] );
+ my ($thistime) = @_;
+ my $timezone = &Apache::lonlocal::gettimezone();
+ my $dt = DateTime->from_epoch(epoch => $thistime)
+ ->set_time_zone($timezone);
+ my $wday = $dt->day_of_week();
+ if ($wday == 7) { $wday = 0; }
+ return ( 'second' => $dt->second(),
+ 'minute' => $dt->minute(),
+ 'hour' => $dt->hour(),
+ 'day' => $dt->day_of_month(),
+ 'month' => $dt->month(),
+ 'year' => $dt->year(),
+ 'weekday' => $wday,
+ 'dayyear' => $dt->day_of_year(),
+ 'dlsav' => $dt->is_dst() );
}
sub utc_string {
@@ -3372,6 +3377,24 @@
sub maketime {
my %th=@_;
+ my ($epoch_time,$timezone,$dt);
+ $timezone = &Apache::lonlocal::gettimezone();
+ eval {
+ $dt = DateTime->new( year => $th{'year'},
+ month => $th{'month'},
+ day => $th{'day'},
+ hour => $th{'hour'},
+ minute => $th{'minute'},
+ second => $th{'second'},
+ time_zone => $timezone,
+ );
+ };
+ if (!$@) {
+ $epoch_time = $dt->epoch;
+ if ($epoch_time) {
+ return $epoch_time;
+ }
+ }
return POSIX::mktime(
($th{'seconds'},$th{'minutes'},$th{'hours'},
$th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));