Consider time zone when creating start/end dates for calendar view methods. Fixes bug #10924

This commit is contained in:
Colin Kuskie 2009-09-16 11:23:47 -07:00
parent c5824ab0e3
commit 96dba300f7
3 changed files with 108 additions and 27 deletions

View file

@ -42,6 +42,7 @@
- fixed #10991: Calendar: bug in Display tab
- added direct value access in DataForm list view
- fixed #10987: EMS Schedule -- No Permission Check
- fixed #10924: Calendar event in last day of month does not display in month/day view
7.7.19
- fixed #10838: Forwarded forum post email to new CS adds reply to original thread

View file

@ -1198,19 +1198,21 @@ The day to look at.
=cut
sub viewDay {
my $self = shift;
my $session = $self->session;
my $params = shift;
my $i18n = WebGUI::International->new($session,"Asset_Calendar");
my $var = $self->getTemplateVars;
my $self = shift;
my $session = $self->session;
my $params = shift;
my $i18n = WebGUI::International->new($session,"Asset_Calendar");
my $var = $self->getTemplateVars;
my $tz = $session->datetime->getTimeZone;
### Get all the events in this time period
# Get the range of the epoch of this day
my $dt = WebGUI::DateTime->new($session, $params->{start});
my $dt = WebGUI::DateTime->new($session, $params->{start});
$dt->set_time_zone($tz);
$dt->truncate( to => "day");
my @events = $self->getEventsIn($dt->toMysql,$dt->clone->add(days => 1)->toMysql);
#### Create the template parameters
# The events
my $pos = -1;
@ -1219,7 +1221,7 @@ sub viewDay {
next EVENT unless $event->canView();
my $dt = $event->getDateTimeStart;
my $hour = $dt->clone->truncate(to=>"hour")->hour;
# Update position if necessary
unless ($hour == $last_hour) {
$pos++;
@ -1231,7 +1233,7 @@ sub viewDay {
"hourM" => ( $hour < 12 ? "am" : "pm"),
};
}
my $eventVar = $event->get;
my %eventDates = $event->getTemplateVars;
push @{$var->{hours}->[$pos]->{events}}, {
@ -1240,8 +1242,8 @@ sub viewDay {
(map { "event".ucfirst($_) => $eventDates{$_} } keys %eventDates),
};
}
# Make the navigation bars
$var->{"pageNextStart"} = $dt->clone->add(days=>1)->toMysql;
$var->{"pageNextUrl"} = $self->getUrl("type=day;start=".$var->{"pageNextStart"});
@ -1259,8 +1261,8 @@ sub viewDay {
$var->{"mdy"} = $dt->mdy;
$var->{"dmy"} = $dt->dmy;
$var->{"epoch"} = $dt->epoch;
# Return the template parameters
return $var;
}
@ -1375,6 +1377,7 @@ sub viewMonth {
#### Get all the events in this time period
# Get the range of the epoch of this month
my $dt = WebGUI::DateTime->new($self->session, $params->{start});
$dt->set_time_zone($tz);
$dt->truncate( to => "month");
my $start = $dt->toMysql;
my $dtEnd = $dt->clone->add(months => 1);

View file

@ -57,7 +57,7 @@ use Data::Dumper;
use WebGUI::Asset::Wobject::Calendar;
use WebGUI::Asset::Event;
plan tests => 11 + scalar @icalWrapTests;
plan tests => 14 + scalar @icalWrapTests;
my $session = WebGUI::Test->session;
@ -69,6 +69,10 @@ $versionTag->set({name=>"Calendar Test"});
WebGUI::Test->tagsToRollback($versionTag);
my $cal = $node->addChild({className=>'WebGUI::Asset::Wobject::Calendar'});
my $windowCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event window testing',
});
$versionTag->commit();
# Test for a sane object type
@ -118,14 +122,9 @@ cmp_deeply(
#
######################################################################
my $windowCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event window testing',
});
my $tz = $session->datetime->getTimeZone();
my $bday = WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday);
my $dt = $bday->clone->truncate(to => 'day');
$dt = $bday->clone->truncate(to => 'day');
my $startDt = $dt->cloneToUserTimeZone->subtract(days => 1);
my $endDt = $dt->cloneToUserTimeZone->add(days => 1);
@ -244,6 +243,8 @@ my $weekCal = $node->addChild({
my $allDayDt = $bday->cloneToUserTimeZone;
my $nextWeekDt = $bday->cloneToUserTimeZone->add(weeks => 1)->truncate( to => 'week')->add(days => 6, hours => 19);
my $allDay = $weekCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
@ -254,6 +255,16 @@ my $allDay = $weekCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $endOfWeek = $weekCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the week',
startDate => $nextWeekDt->toDatabaseDate,
endDate => $nextWeekDt->toDatabaseDate,
startTime => $nextWeekDt->toDatabaseTime,
endTime => $nextWeekDt->clone->add(hours => 1)->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag3 = WebGUI::VersionTag->getWorking($session);
$tag3->commit;
WebGUI::Test->tagsToRollback($tag3);
@ -272,6 +283,20 @@ cmp_deeply(
'viewWeek: all day event is only in 1 day when time zones line up correctly'
);
$weekVars = $weekCal->viewWeek({ start => $nextWeekDt });
@eventBins = ();
foreach my $day (@{ $weekVars->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
push @eventBins, $day->{dayOfWeek};
}
}
cmp_deeply(
\@eventBins,
[ 7 ],
'... end of week event in proper bin, considering time zone'
);
################################################################
#
# wrapIcal
@ -297,9 +322,10 @@ my $monthCal = $node->addChild({
title => 'Calendar for doing event span testing, month',
});
my $allDayDt = $bday->cloneToUserTimeZone;
$allDayDt = $bday->cloneToUserTimeZone;
my $nextMonthDt = $bday->cloneToUserTimeZone->add(months => 1)->truncate( to => 'month')->add(days => 29, hours => 19);
my $allDay = $monthCal->addChild({
$allDay = $monthCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
@ -309,12 +335,22 @@ my $allDay = $monthCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $endOfMonth = $monthCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the month',
startDate => $nextMonthDt->toDatabaseDate,
endDate => $nextMonthDt->toDatabaseDate,
startTime => $nextMonthDt->toDatabaseTime,
endTime => $nextMonthDt->clone->add(hours => 1)->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 = ();
@eventBins = ();
foreach my $week ( @{ $monthVars->{weeks} } ) {
foreach my $day (@{ $week->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
@ -329,6 +365,22 @@ cmp_deeply(
'viewMonth: all day event is only in 1 day when time zones line up correctly'
);
$monthVars = $monthCal->viewMonth({ start => $nextMonthDt });
@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,
[ 30 ],
'... end of month event in proper bin'
);
######################################################################
#
@ -341,9 +393,10 @@ my $dayCal = $node->addChild({
title => 'Calendar for doing event span testing, day',
});
my $allDayDt = $bday->cloneToUserTimeZone;
$allDayDt = $bday->cloneToUserTimeZone;
my $nextDayDt = $bday->cloneToUserTimeZone->add(days => 1)->truncate( to => 'day')->add(hours => 19);
my $allDay = $dayCal->addChild({
$allDay = $dayCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
@ -353,10 +406,34 @@ my $allDay = $dayCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $nextDay = $dayCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the next day',
startDate => $nextDayDt->toDatabaseDate,
endDate => $nextDayDt->toDatabaseDate,
startTime => $nextDayDt->toDatabaseTime,
endTime => $nextDayDt->clone->add(hours => 1)->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag5 = WebGUI::VersionTag->getWorking($session);
$tag5->commit;
WebGUI::Test->tagsToRollback($tag5);
my $hourVars = $dayCal->viewDay({ start => $nextDayDt });
@eventBins = ();
foreach my $slot (@{ $hourVars->{hours} }) {
if (exists $slot->{events} and scalar @{ $slot->{events} } > 0) {
push @eventBins, $slot->{hour24};
}
}
cmp_deeply(
\@eventBins,
[ 19 ],
'... end of day event in proper bin'
);
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Lots more to test');