From 71b06ee4b81aacd0a58e4a2450b782ec3909ec1f Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 13 May 2016 13:42:33 +0200 Subject: * method for determining full weeks containing specific month, based on a timezone preference --- app/php/facades/CalendarFacade.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php index 48dda8e..1f78594 100644 --- a/app/php/facades/CalendarFacade.php +++ b/app/php/facades/CalendarFacade.php @@ -4,6 +4,7 @@ Prado::using('Application.facades.Facade'); Prado::using('Application.facades.EventFacade'); Prado::using('Application.dto.CalendarDTO'); Prado::using('Application.dto.CalendarGroupDTO'); +Prado::using('Application.dto.TimezoneDTO'); Prado::using('Application.model.Calendar'); Prado::using('Application.model.Category'); Prado::using('Application.model.UserPreference'); @@ -190,6 +191,22 @@ class CalendarFacade extends Facade { return NULL; } + public function getCalendarBoundaries($year, $month, TimezoneDTO $timezone) { + $firstDay = new DateTime(sprintf('%d-%02d', $year, $month), + new DateTimeZone($timezone->Name)); + $firstDayAfter = clone $firstDay; + $firstDayAfter->modify('last day of this month')->modify('+1 day'); + $firstDayOfTheWeek = $timezone->FirstDayOfTheWeek; + if ($firstDay->format('D') !== $firstDayOfTheWeek) { + $firstDay->modify('last ' . $firstDayOfTheWeek); + } + if ($firstDayAfter->format('D') !== $firstDayOfTheWeek) { + $firstDayAfter->modify('next ' . $firstDayOfTheWeek); + } + $firstDayAfter->modify('-1 day'); + return [$firstDay, $firstDayAfter]; + } + } ?> -- cgit v1.2.3