Forward porting calendar non-inclusive end times fix.

This commit is contained in:
Colin Kuskie 2009-08-03 20:05:34 +00:00
parent c0fe0a7765
commit ecd89d349a
4 changed files with 354 additions and 265 deletions

View file

@ -4,15 +4,19 @@ use strict;
our $VERSION = "0.0.0"; our $VERSION = "0.0.0";
#################################################################### =head1 LEGAL
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#################################################################### -------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license WebGUI is Copyright 2001-2009 Plain Black Corporation.
# (docs/license.txt) that came with this distribution before using -------------------------------------------------------------------
# this software. Please read the legal notices (docs/legal.txt) and the license
#################################################################### (docs/license.txt) that came with this distribution before using
# http://www.plainblack.com info@plainblack.com this software.
#################################################################### -------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use Tie::IxHash; use Tie::IxHash;
use Carp qw(croak); use Carp qw(croak);
@ -29,17 +33,16 @@ use WebGUI::DateTime;
=head1 Name =head1 NAME
WebGUI::Asset::Event
=head1 DESCRIPTION
Package to handle events.
=head1 Description =head1 METHODS
=head1 Synopsis
=head1 Methods
=cut =cut
@ -398,7 +401,8 @@ sub getDateTimeEnd {
Since the iCal standard is that ending dates are non-inclusive (they Since the iCal standard is that ending dates are non-inclusive (they
do not include the second at the end of the time period), this method do not include the second at the end of the time period), this method
provide a copy of the DateTime object that is 1 second earlier than provide a copy of the DateTime object that is 1 second earlier than
the set ending time. the set ending time. If the event has no ending time, then the ending
time is 1 second before midnight.
It's just one line of DateTime code to adjust this on any object, but It's just one line of DateTime code to adjust this on any object, but
this is encapsulated here to make sure that the same amount of time this is encapsulated here to make sure that the same amount of time
@ -409,7 +413,9 @@ is used EVERYWHERE.
sub getDateTimeEndNI { sub getDateTimeEndNI {
my $self = shift; my $self = shift;
my $dt = $self->getDateTimeEnd; my $dt = $self->getDateTimeEnd;
$dt->subtract(seconds => 1); if ($self->get('endTime') ) {
$dt->subtract(seconds => 1);
}
return $dt; return $dt;
} }
@ -1300,7 +1306,6 @@ sub getTemplateVars {
# End date/time # End date/time
my $dtEnd = $self->getDateTimeEnd; my $dtEnd = $self->getDateTimeEnd;
my $dtEndNI = $self->getDateTimeEndNI;
$var{ "endDateSecond" } = sprintf "%02d", $dtEnd->second; $var{ "endDateSecond" } = sprintf "%02d", $dtEnd->second;
$var{ "endDateMinute" } = sprintf "%02d", $dtEnd->minute; $var{ "endDateMinute" } = sprintf "%02d", $dtEnd->minute;

View file

@ -1338,7 +1338,7 @@ sub viewMonth {
next EVENT unless $event->canView(); next EVENT unless $event->canView();
# Get the WebGUI::DateTime objects # Get the WebGUI::DateTime objects
my $dt_event_start = $event->getDateTimeStart; my $dt_event_start = $event->getDateTimeStart;
my $dt_event_end = $event->getDateTimeEnd; my $dt_event_end = $event->getDateTimeEndNI;
# Prepare the template variables # Prepare the template variables
my %eventTemplateVariables = $self->getEventVars($event); my %eventTemplateVariables = $self->getEventVars($event);

View file

@ -19,7 +19,7 @@ use WebGUI::Asset::Event;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
use Test::Deep; use Test::Deep;
plan tests => 10; plan tests => 13;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
@ -47,6 +47,7 @@ my $properties = {
my $event = $cal->addChild($properties, $properties->{id}); my $event = $cal->addChild($properties, $properties->{id});
is($event->isAllDay, 0, 'isAllDay is zero since it has a start and end time'); is($event->isAllDay, 0, 'isAllDay is zero since it has a start and end time');
cmp_ok($event->getDateTimeEnd, '>', $event->getDateTimeEndNI, 'getDateTimeEndNI is less than getDateTimeEnd');
my %templateVars = $event->getTemplateVars(); my %templateVars = $event->getTemplateVars();
is($templateVars{isOneDay}, 1, 'getTemplateVars: isOneDay with start times'); is($templateVars{isOneDay}, 1, 'getTemplateVars: isOneDay with start times');
@ -62,6 +63,7 @@ $properties->{url} = 'event-asset-test2';
my $event2 = $cal->addChild($properties, $properties->{id}); my $event2 = $cal->addChild($properties, $properties->{id});
is($event2->isAllDay, 1, 'isAllDay is zero since it has no start or end time'); is($event2->isAllDay, 1, 'isAllDay is zero since it has no start or end time');
cmp_ok($event2->getDateTimeEnd, '==', $event2->getDateTimeEndNI, 'getDateTimeEndNI is the same as getDateTimeEnd, due to no end time');
%templateVars = $event2->getTemplateVars(); %templateVars = $event2->getTemplateVars();
is($templateVars{dateSpan}, 'Wednesday, August 16', 'getTemplateVars: dateSpan with no times'); is($templateVars{dateSpan}, 'Wednesday, August 16', 'getTemplateVars: dateSpan with no times');
@ -82,4 +84,15 @@ is($event3->isAllDay, 1, 'isAllDay is zero since it has no start or end time, ev
is($templateVars{dateSpan}, 'Wednesday, August 16 • Thursday, August 17 ', 'getTemplateVars: dateSpan with no times, across two days'); is($templateVars{dateSpan}, 'Wednesday, August 16 • Thursday, August 17 ', 'getTemplateVars: dateSpan with no times, across two days');
is($templateVars{isOneDay}, 0, 'getTemplateVars: isOneDay with different start and end dates'); is($templateVars{isOneDay}, 0, 'getTemplateVars: isOneDay with different start and end dates');
cmp_ok($event3->getDateTimeEnd, '>', $event3->getDateTimeEndNI, 'getDateTimeEndNI is less than getDateTimeEnd'); cmp_ok($event3->getDateTimeEnd, '==', $event3->getDateTimeEndNI, 'getDateTimeEndNI is the same as getDateTimeEnd');
$properties->{startDate} = '2000-08-16';
$properties->{endDate} = '2000-08-17';
$properties->{startTime} = '00:00:00';
$properties->{endTime} = '00:00:00';
$properties->{id} = 'EventAssetTest00000004';
$properties->{url} = 'event-asset-test4';
my $event4 = $cal->addChild($properties, $properties->{id});
cmp_ok($event4->getDateTimeEnd, '>', $event4->getDateTimeEndNI, 'getDateTimeEndNI is less than getDateTimeEnd');

View file

@ -57,7 +57,7 @@ use Data::Dumper;
use WebGUI::Asset::Wobject::Calendar; use WebGUI::Asset::Wobject::Calendar;
use WebGUI::Asset::Event; use WebGUI::Asset::Event;
plan tests => 10 + scalar @icalWrapTests; plan tests => 11 + scalar @icalWrapTests;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
@ -258,9 +258,9 @@ my $tag3 = WebGUI::VersionTag->getWorking($session);
$tag3->commit; $tag3->commit;
WebGUI::Test->tagsToRollback($tag3); WebGUI::Test->tagsToRollback($tag3);
my $allVars = $weekCal->viewWeek({ start => $bday }); my $weekVars = $weekCal->viewWeek({ start => $bday });
my @eventBins = (); my @eventBins = ();
foreach my $day (@{ $allVars->{days} }) { foreach my $day (@{ $weekVars->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) { if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
push @eventBins, $day->{dayOfWeek}; push @eventBins, $day->{dayOfWeek};
} }
@ -286,6 +286,77 @@ foreach my $test (@icalWrapTests) {
is ($wrapOut, $out, $comment); is ($wrapOut, $out, $comment);
} }
######################################################################
#
# viewMonth
#
######################################################################
my $monthCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event span testing, month',
});
my $allDayDt = $bday->cloneToUserTimeZone;
my $allDay = $monthCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
endDate => $allDayDt->clone->add(days => 1)->toDatabaseDate,
startTime => $allDayDt->clone->truncate(to => 'day')->toDatabaseTime,
endTime => $allDayDt->clone->add(days => 1)->truncate(to => 'day')->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag4 = WebGUI::VersionTag->getWorking($session);
$tag4->commit;
WebGUI::Test->tagsToRollback($tag4);
my $monthVars = $monthCal->viewMonth({ start => $bday });
my @eventBins = ();
foreach my $week ( @{ $monthVars->{weeks} } ) {
foreach my $day (@{ $week->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
push @eventBins, $day->{dayMonth};
}
}
}
cmp_deeply(
\@eventBins,
[ 16 ],
'viewMonth: all day event is only in 1 day when time zones line up correctly'
);
######################################################################
#
# viewDay
#
######################################################################
my $dayCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event span testing, day',
});
my $allDayDt = $bday->cloneToUserTimeZone;
my $allDay = $dayCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
endDate => $allDayDt->clone->add(days => 1)->toDatabaseDate,
startTime => $allDayDt->clone->truncate(to => 'day')->toDatabaseTime,
endTime => $allDayDt->clone->add(days => 1)->truncate(to => 'day')->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag5 = WebGUI::VersionTag->getWorking($session);
$tag5->commit;
WebGUI::Test->tagsToRollback($tag5);
TODO: { TODO: {
local $TODO = "Tests to make later"; local $TODO = "Tests to make later";
ok(0, 'Lots more to test'); ok(0, 'Lots more to test');