From 2180b9bf91441176d435583cf5904a1a5a47de4c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 19 Jan 2007 06:25:43 +0000 Subject: [PATCH] Added a test to see if clone would duplicate the session. It does. Subclassed DateTime's from_object method, which was secretely deleting the internal session variable. There is probably a more robust way to do this, such as by "...implementing the utc_rd_values() method as the from_object docs suggest. Finished fixing the bug with time zone errors in editing an event. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Event.pm | 13 +++++-------- lib/WebGUI/DateTime.pm | 19 ++++++++++++++++++- t/DateTime.pm | 5 +++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ca0302e1a..444612e1c 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fix: Checkbox is no longer available when creating custom profile fields - fix: profile fields do not ever set the default value - fix: CS email message shows up as an attachment + - fix: Calendar: start/end date time off in edit interface (perlDreamer Consulting, LLC) 7.3.5 diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 43bee219b..0499f407e 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -289,13 +289,13 @@ sub getDateTimeStart if ($time) { - my $dt = new WebGUI::DateTime($self->session, $date." ".$time); + my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); $dt->set_time_zone($tz); return $dt; } else { - my $dt = new WebGUI::DateTime($self->session, $date." 00:00:00"); + my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00"); return $dt; } } @@ -333,13 +333,13 @@ sub getDateTimeEnd if ($time) { - my $dt = new WebGUI::DateTime($self->session, $date." ".$time); + my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); $dt->set_time_zone($tz); return $dt; } else { - my $dt = new WebGUI::DateTime($self->session, $date." 23:59:59"); + my $dt = WebGUI::DateTime->new($self->session, $date." 23:59:59"); return $dt; } } @@ -1767,22 +1767,19 @@ sub www_edit # end date $default_start->add(hours => 1); - #my ($endDate,$endTime) = split / /, $self->getDateTimeEnd->toMysql my ($endDate,$endTime) = split / /, $self->getDateTimeEnd->toUserTimeZone unless $func eq "add" || $self->get("assetId") eq "new"; $var->{"formEndDate"} = WebGUI::Form::date($session, { name => "endDate", value => $form->process("endDate") || $endDate, - #defaultValue => $default_start->toMysqlDate, defaultValue => $default_start->toUserTimeZoneDate, }); $var->{"formEndTime"} = WebGUI::Form::timeField($session, { name => "endTime", value => $form->process("endTime") || $endTime, - defaultValue => $default_start->toMysqlTime, - #defaultValue => $default_start->toUserTimeZoneTime, + defaultValue => $default_start->toUserTimeZoneTime, }); # time diff --git a/lib/WebGUI/DateTime.pm b/lib/WebGUI/DateTime.pm index adc1c22f8..363d3f687 100755 --- a/lib/WebGUI/DateTime.pm +++ b/lib/WebGUI/DateTime.pm @@ -205,6 +205,23 @@ sub cloneToUserTimeZone { ####################################################################### +=head2 from_object + +Handle copying all WebGUI::DateTime specific data. This is a class method. + +=cut + +sub from_object { + my $class = shift; + my %args = @_; + my $session = $args{object}->session; + my $copy = $class->SUPER::from_object(@_); + $copy->session($session); + return $copy; +} + +####################################################################### + =head2 toDatabase Returns a MySQL Date/Time string in the UTC time zone @@ -398,7 +415,7 @@ This is going to have to be changed eventually so you don't have to set the sess =cut sub session { - my $self = shift; + my $self = shift; my $session = shift; if($session) { diff --git a/t/DateTime.pm b/t/DateTime.pm index a861fb817..d740e8c7d 100644 --- a/t/DateTime.pm +++ b/t/DateTime.pm @@ -23,7 +23,7 @@ my $session = WebGUI::Test->session; # put your tests here -my $numTests = 1 + 12; +my $numTests = 1 + 13; plan tests => $numTests; my $loaded = use_ok("WebGUI::DateTime"); @@ -46,7 +46,8 @@ is($dt->toDatabaseTime, "21:12:45", "toDatabaseTime returns the ident $session->user({user => $timeZoneUser}); my $copiedDt = $dt->cloneToUserTimeZone; -isa_ok($copiedDt, "WebGUI::DateTime", "cloneToUserTimeZone"); +isa_ok($copiedDt, "WebGUI::DateTime", "cloneToUserTimeZone"); +isa_ok($copiedDt->session, "WebGUI::Session", "cloneToUserTimeZone also copies over the session object"); is($copiedDt->time_zone()->name, "America/Hermosillo", "cloned object has correct time zone"); is($dt->time_zone()->name, "UTC", "original object is still UTC");