diff options
author | emkael <emkael@tlen.pl> | 2016-05-13 13:42:33 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-13 13:50:13 +0200 |
commit | 71b06ee4b81aacd0a58e4a2450b782ec3909ec1f (patch) | |
tree | b58249b9b4307328dffbdb5af5af1c1284c32e66 | |
parent | a798696dea21ccf90c18c5a5fb47bd845e5a885b (diff) |
* method for determining full weeks containing specific month, based on a timezone preference
-rw-r--r-- | app/php/facades/CalendarFacade.php | 17 |
1 files changed, 17 insertions, 0 deletions
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]; + } + } ?> |