From eb9d4ba5466352c7091dca37c8e2baeaf5036c27 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Sun, 4 Dec 2005 22:41:56 +0000 Subject: [PATCH] adding epochToArray to EventsCalendar.pm as a kludge b/c it's no longer in DateTime.pm. --- lib/WebGUI/Asset/Wobject/EventsCalendar.pm | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/EventsCalendar.pm b/lib/WebGUI/Asset/Wobject/EventsCalendar.pm index 529fd0508..47fff0618 100644 --- a/lib/WebGUI/Asset/Wobject/EventsCalendar.pm +++ b/lib/WebGUI/Asset/Wobject/EventsCalendar.pm @@ -83,6 +83,27 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 epochToArray ( epoch ) + +Returns an array date. + +=head3 epoch + +The number of seconds since January 1, 1970. + +=cut + +sub epochToArray { + my $timeZone = $session{user}{timeZone} || "America/Chicago"; + use DateTime; + my $dt = DateTime->from_epoch( epoch =>shift, time_zone=>$timeZone); + my @date = split / /, $dt->strftime("%Y %m %d %H %M %S"); + @date = map {$_ += 0} @date; + return @date; +} + #------------------------------------------------------------------- @@ -232,7 +253,7 @@ sub view { $maxDate = WebGUI::DateTime::addToDate($minDate,0,1,0); } #WebGUI::ErrorHandler::warn("calMonthStart:".$calMonthStart." calMonthEnd:".$calMonthEnd); - my @now = WebGUI::DateTime::epochToArray(WebGUI::DateTime::time()); + my @now = epochToArray(WebGUI::DateTime::time()); my $calHasEvent = 0; #monthcount minus i is the number of months remaining to be processed. for (my $i=$calMonthStart;$i<=$calMonthEnd;$i++) { @@ -240,7 +261,7 @@ sub view { my $monthHasEvent = 0; my $thisMonth = WebGUI::DateTime::addToDate($minDate,0,($i-1),0); my ($monthStart, $monthEnd) = WebGUI::DateTime::monthStartEnd($thisMonth); - my @thisMonthDate = WebGUI::DateTime::epochToArray($thisMonth); + my @thisMonthDate = epochToArray($thisMonth); #Check month to see if it is in the allowed month range. End loop if it's not. if ($thisMonth > $maxDate) { $i = $calMonthEnd; @@ -279,7 +300,7 @@ sub view { #cycle through each day in the event, pushing the event's day listing into the proper day. for (my $i=$eventCycleStart; $i<=$eventCycleStop; $i++) { #create an array for the specific day in the event. - my @date = WebGUI::DateTime::epochToArray(WebGUI::DateTime::addToDate($eventStartDate,0,0,$i)); + my @date = epochToArray(WebGUI::DateTime::addToDate($eventStartDate,0,0,$i)); # if the event goes past the end of this month, halt the loop. # No need to continue processing days that aren't in this month. if ($monthEnd < (WebGUI::DateTime::addToDate($eventStartDate,0,0,$i) - 1)) { @@ -341,7 +362,7 @@ sub view { }); $dayOfWeekCounter++; } - my @date = WebGUI::DateTime::epochToArray($thisMonth); + my @date = epochToArray($thisMonth); my @dayloop; for (my $dayCounter=1; $dayCounter <= $daysInMonth; $dayCounter++) { #----------------------------------------------------------------------------