[LON-CAPA-cvs] cvs: loncom /interface lonclonecourse.pm
raeburn
raeburn at source.lon-capa.org
Wed Jan 20 19:12:38 EST 2016
raeburn Thu Jan 21 00:12:38 2016 EDT
Modified files:
/loncom/interface lonclonecourse.pm
Log:
- Bug 6810
For cloning when the number of days date shift is an integer, the
time component of a date parameter will be kept the same if the shift
causes the value to change from daylight savings to standard time
(or vice versa).
Index: loncom/interface/lonclonecourse.pm
diff -u loncom/interface/lonclonecourse.pm:1.11 loncom/interface/lonclonecourse.pm:1.12
--- loncom/interface/lonclonecourse.pm:1.11 Tue Jun 23 17:49:06 2015
+++ loncom/interface/lonclonecourse.pm Thu Jan 21 00:12:38 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network
# routines for clone a course
#
-# $Id: lonclonecourse.pm,v 1.11 2015/06/23 17:49:06 musolffc Exp $
+# $Id: lonclonecourse.pm,v 1.12 2016/01/21 00:12:38 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,6 +30,8 @@
package Apache::lonclonecourse;
use LONCAPA;
use Apache::lonnet;
+use DateTime();
+use DateTime::TimeZone;
# ================================================ Get course directory listing
@@ -148,6 +150,22 @@
my $delta=$date_shift*60*60*24;
my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
+ my $origtz;
+ if (($date_mode) && ($date_mode ne 'preserve') && ($date_shift) &&
+ (int($date_shift) == $date_shift)) {
+ $origtz = $origcrsdata{'timezone'};
+ if ($origtz eq '') {
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($origcrsdata{'domain'});
+ if ($domdefaults{'timezone_def'} ne '') {
+ $origtz = $domdefaults{'timezone_def'};
+ }
+ }
+ if ($origtz eq '') {
+ $origtz = 'local';
+ } elsif (!DateTime::TimeZone->is_valid_name($origtz)) {
+ $origtz = 'local';
+ }
+ }
my %data=&Apache::lonnet::dump
('resourcedata',$origcrsdata{'domain'},$origcrsdata{'num'});
$origcrsid=~s/^\///;
@@ -195,14 +213,24 @@
# date_mode other: do not transfer dates
if (($date_mode) && ($date_mode ne 'preserve')) {
if ($data{$key.'.type'}=~/^date_(start|end)$/) {
- if ($date_mode eq 'shift') {
- $newdata{$thiskey}=$newdata{$thiskey}+$delta;
- } else {
- delete($newdata{$thiskey});
- delete($newdata{$thiskey.'.type'});
- }
+ if ($date_mode eq 'shift') {
+ if (($date_shift) && ($date_shift == int($date_shift))) {
+ my $dt = DateTime->from_epoch(epoch => $newdata{$thiskey})
+ ->set_time_zone($origtz);
+ if (($origtz eq 'local') && (!$ENV{TZ})) {
+ $ENV{TZ} = $dt->time_zone()->name();
+ }
+ $dt->add(days => int($date_shift));
+ $newdata{$thiskey} = $dt->epoch();
+ } else {
+ $newdata{$thiskey} = $newdata{$thiskey}+$delta;
+ }
+ } else {
+ delete($newdata{$thiskey});
+ delete($newdata{$thiskey.'.type'});
+ }
}
- }
+ }
}
return &Apache::lonnet::put
('resourcedata',\%newdata,$newcrsdata{'domain'},$newcrsdata{'num'});
More information about the LON-CAPA-cvs
mailing list