From 1d99ee451ea7cfbd5a276dc8359decf5b8c3c641 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 13 Sep 2010 11:04:03 -0700 Subject: [PATCH] Allow users to enter 24:00:00 by hand, and have the Event handle it correctly. Fixes bug #11788 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Event.pm | 31 ++++++++++++++++++++++++++++++- t/Asset/Event.t | 20 ++++++++++++++++---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f20908c74..7dc1bd7af 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -3,6 +3,7 @@ - fixed #11854: CS doesn't return Not Found page - fixed #11746: Thingy import CSV only supports one line ending - fixed #11833: Recheck for losing Product Images + - fixed #11788: Calendar - Can't enter Midnight - Broke page layout 7.10.0 - fixed #11812: Checking www_ajaxSave's response in the cart js, urlencoding post parameters diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 10b3b1c58..a66a56c17 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1711,8 +1711,37 @@ Wrap update so that isHidden is always set to be a 1. =cut sub update { - my $self = shift; + my $self = shift; my $properties = shift; + my $session = $self->session; + if (my $startTime = $properties->{startTime}) { + my ($startHour, $startMinute, $startSecond) = $startTime =~ /^ (\d+) : (\d+) (?: :(\d+)) /x; + if ($startHour > 23) { + $startHour = 0; + my $startDate = exists $properties->{startDate} ? $properties->{startDate} : $self->get('startDate'); + $session->log->warn('startDate: '. $startDate); + my $startDt = WebGUI::DateTime->new($session, $startDate); + $startDt->add(days => 1); + $properties->{startDate} = $startDt->toMysqlDate; + $session->log->warn('startDate: '. $properties->{startDate}); + $startSecond = '00' if ! $startSecond; + $properties->{startTime} = sprintf '%02d:%02d:%02d', $startHour, $startMinute, $startSecond; + } + } + if (my $endTime = $properties->{endTime}) { + my ($endHour, $endMinute, $endSecond) = $endTime =~ /^ (\d+) : (\d+) (?: :(\d+)) /x; + if ($endHour > 23) { + $endHour = 0; + my $endDate = exists $properties->{endDate} ? $properties->{endDate} : $self->get('endDate'); + $session->log->warn('endDate: '. $endDate); + my $endDt = WebGUI::DateTime->new($session, $endDate); + $endDt->add(days => 1); + $properties->{endDate} = $endDt->toMysqlDate; + $session->log->warn('endDate: '. $properties->{endDate}); + $endSecond = '00' if ! $endSecond; + $properties->{endTime} = sprintf '%02d:%02d:%02d', $endHour, $endMinute, $endSecond; + } + } return $self->SUPER::update({%$properties, isHidden => 1}); } diff --git a/t/Asset/Event.t b/t/Asset/Event.t index 217df8aac..93cf60e8b 100644 --- a/t/Asset/Event.t +++ b/t/Asset/Event.t @@ -19,7 +19,7 @@ use WebGUI::Asset::Event; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 18; +plan tests => 22; my $session = WebGUI::Test->session; @@ -122,12 +122,24 @@ my $eventStorage = WebGUI::Storage->create($session); WebGUI::Test->addToCleanup($eventStorage); $properties3->{storageId} = $eventStorage->getId; -my $event6 = $cal->addChild($properties3, $properties3->{id}); - -sleep 2; +my $event6 = $cal->addChild($properties3, $properties3->{id}, time()-5); my $event6a = $event6->addRevision({ title => 'Event with storage', }, undef, { skipAutoCommitWorkflows => 1, }); ok($session->id->valid($event6a->get('storageId')), 'addRevision gives the new revision a valid storageId'); isnt($event6a->get('storageId'), $event6->get('storageId'), '... and it is different from the previous revision'); my $versionTag2 = WebGUI::VersionTag->getWorking($session); WebGUI::Test->addToCleanup($versionTag2); + +my $event7 = $cal->addChild({ + className => 'WebGUI::Asset::Event', + startDate => '2000-08-31', + startTime => '24:00:00', + endDate => '2000-09-01', + endTime => '24:00:00', +}); + +is ($event7->get('startTime'), '00:00:00', 'startTime set to 00:00:00 if the hour is more than 23'); +is ($event7->get('startDate'), '2000-09-01', 'startDate bumped by 1 day'); + +is ($event7->get('endTime'), '00:00:00', 'endTime set to 00:00:00 if the hour is more than 23'); +is ($event7->get('endDate'), '2000-09-02', 'endDate bumped by 1 day');