Add an Event method for returning a non-inclusive end DataTime object.
Have Calendar use that for determining the end of a week in viewWeek. Fix getEventsIn to do all comparisons in UTC so that extra events are not added in.
This commit is contained in:
parent
f04a162ea3
commit
1bcae0d3bc
4 changed files with 213 additions and 37 deletions
|
|
@ -391,6 +391,28 @@ sub getDateTimeEnd {
|
|||
}
|
||||
}
|
||||
|
||||
####################################################################
|
||||
|
||||
=head2 getDateTimeEndNI
|
||||
|
||||
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
|
||||
provide a copy of the DateTime object that is 1 second earlier than
|
||||
the set ending time.
|
||||
|
||||
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
|
||||
is used EVERYWHERE.
|
||||
|
||||
=cut
|
||||
|
||||
sub getDateTimeEndNI {
|
||||
my $self = shift;
|
||||
my $dt = $self->getDateTimeEnd;
|
||||
$dt->subtract(seconds => 1);
|
||||
return $dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1277,7 +1299,8 @@ sub getTemplateVars {
|
|||
$var{ "startDateEpoch" } = $dtStart->epoch;
|
||||
|
||||
# End date/time
|
||||
my $dtEnd = $self->getDateTimeEnd;
|
||||
my $dtEnd = $self->getDateTimeEnd;
|
||||
my $dtEndNI = $self->getDateTimeEndNI;
|
||||
|
||||
$var{ "endDateSecond" } = sprintf "%02d", $dtEnd->second;
|
||||
$var{ "endDateMinute" } = sprintf "%02d", $dtEnd->minute;
|
||||
|
|
|
|||
|
|
@ -674,11 +674,11 @@ This is the main API method to get events from a calendar, so it must be flexibl
|
|||
|
||||
=head3 startDate
|
||||
|
||||
A date with optional time in MySQL format.
|
||||
A date, with optional time, in UTC, in MySQL format.
|
||||
|
||||
=head3 endDate
|
||||
|
||||
A date with optional time in MySQL format.
|
||||
A date, with optional time, in UTC, in MySQL format.
|
||||
|
||||
=head3 options
|
||||
|
||||
|
|
@ -700,8 +700,6 @@ sub getEventsIn {
|
|||
$params->{order} = '' if $params->{order} !~ /^(?:time|sequencenumber)/i;
|
||||
my $order_by_type = $params->{order} ? lc($params->{order}) : $self->get('sortEventsBy');
|
||||
|
||||
my $tz = $self->session->datetime->getTimeZone;
|
||||
|
||||
# Warn and return undef if no startDate or endDate
|
||||
unless ($start && $end) {
|
||||
$self->session->errorHandler->warn("WebGUI::Asset::Wobject::Calendar->getEventsIn() called with not enough arguments at ".join('::',(caller)[1,2]));
|
||||
|
|
@ -710,14 +708,9 @@ sub getEventsIn {
|
|||
|
||||
# Create objects and adjust for timezone
|
||||
|
||||
my ($startDate,$startTime) = split / /, $start;
|
||||
my ($endDate,$endTime) = split / /, $end;
|
||||
|
||||
#use Data::Dumper;
|
||||
#$self->session->errorHandler->warn( Dumper [caller(1), caller(2), caller(3)] );
|
||||
my $startTz = WebGUI::DateTime->new($self->session, mysql => $start, time_zone => $tz)->set_time_zone("UTC")->toMysql;
|
||||
my $endTz = WebGUI::DateTime->new($self->session, mysql => $end, time_zone => $tz)->set_time_zone("UTC")->toMysql;
|
||||
|
||||
my ($startDate) = split / /, $start;
|
||||
my ($endDate) = split / /, $end;
|
||||
|
||||
my $where
|
||||
= qq{
|
||||
(
|
||||
|
|
@ -730,8 +723,8 @@ sub getEventsIn {
|
|||
)
|
||||
)
|
||||
|| (
|
||||
CONCAT(Event.startDate,' ',Event.startTime) >= '$startTz'
|
||||
&& CONCAT(Event.startDate,' ',Event.startTime) < '$endTz'
|
||||
CONCAT(Event.startDate,' ',Event.startTime) >= '$start'
|
||||
&& CONCAT(Event.startDate,' ',Event.startTime) < '$end'
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -749,7 +742,6 @@ sub getEventsIn {
|
|||
|
||||
my $orderby = join ',', @order_priority;
|
||||
|
||||
|
||||
my $events
|
||||
= $self->getLineage(["descendants"], {
|
||||
returnObjects => 1,
|
||||
|
|
@ -758,9 +750,9 @@ sub getEventsIn {
|
|||
orderByClause => $orderby,
|
||||
whereClause => $where,
|
||||
});
|
||||
|
||||
|
||||
#? Perhaps use Stow to cache Events ?#
|
||||
|
||||
|
||||
return @{$events};
|
||||
}
|
||||
|
||||
|
|
@ -1441,6 +1433,7 @@ sub viewWeek {
|
|||
#### Get all the events in this time period
|
||||
# Get the range of the epoch of this week
|
||||
my $dt = WebGUI::DateTime->new($self->session, $params->{start});
|
||||
$dt->set_time_zone($tz);
|
||||
$dt->truncate( to => "day");
|
||||
|
||||
# Apply First Day of Week settings
|
||||
|
|
@ -1479,7 +1472,7 @@ sub viewWeek {
|
|||
# Get the week this event is in, and add it to that week in
|
||||
# the template variables
|
||||
my $dt_event_start = $event->getDateTimeStart;
|
||||
my $dt_event_end = $event->getDateTimeEnd;
|
||||
my $dt_event_end = $event->getDateTimeEndNI;
|
||||
|
||||
#Handle events that start before this week or end after this week.
|
||||
if ($dt_event_start < $dt) {
|
||||
|
|
@ -1491,7 +1484,7 @@ sub viewWeek {
|
|||
}
|
||||
|
||||
my $start_dow = ($dt_event_start->day_of_week - $first_dow) % 7;
|
||||
my $end_dow = ($dt_event_end->day_of_week - $first_dow) % 7;
|
||||
my $end_dow = ($dt_event_end->day_of_week - $first_dow) % 7;
|
||||
|
||||
my $sequence_number = $session->db->dbh->selectcol_arrayref(
|
||||
"SELECT sequenceNumber FROM Event WHERE assetId = ? ORDER BY revisionDate desc LIMIT 1",
|
||||
|
|
@ -1645,26 +1638,26 @@ sub viewWeek {
|
|||
# Get the week this event is in, and add it to that week in
|
||||
# the template variables
|
||||
my $dt_event_start = $event->getDateTimeStart;
|
||||
my $dt_event_end = $event->getDateTimeEnd;
|
||||
my $dt_event_end = $event->getDateTimeEndNI;
|
||||
|
||||
#Handle events that start before this week or end after this week.
|
||||
if ($dt_event_start < $dt) {
|
||||
$dt_event_start = $dt;
|
||||
$dt_event_start = $dt->clone;
|
||||
}
|
||||
|
||||
if ($dt_event_end > $dtEnd) {
|
||||
$dt_event_end = $dtEnd;
|
||||
$dt_event_end = $dtEnd->clone;
|
||||
}
|
||||
|
||||
my $start_dow = ($dt_event_start->day_of_week - $first_dow) % 7;
|
||||
my $end_dow = ($dt_event_end->day_of_week - $first_dow) % 7;
|
||||
my $end_dow = ($dt_event_end->day_of_week - $first_dow) % 7;
|
||||
|
||||
my %eventTemplateVariables = $self->getEventVars($event);
|
||||
|
||||
foreach my $weekDay ($start_dow .. $end_dow) {
|
||||
my $eventAssetId = $event->get( 'assetId' );
|
||||
|
||||
my %hash = %eventTemplateVariables;
|
||||
my %hash = %eventTemplateVariables;
|
||||
|
||||
if ($sort_by_sequence && $can_edit_order) {
|
||||
if (1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue