summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-05-13 13:42:33 +0200
committeremkael <emkael@tlen.pl>2016-05-13 13:50:13 +0200
commit71b06ee4b81aacd0a58e4a2450b782ec3909ec1f (patch)
treeb58249b9b4307328dffbdb5af5af1c1284c32e66 /app/php
parenta798696dea21ccf90c18c5a5fb47bd845e5a885b (diff)
* method for determining full weeks containing specific month, based on a timezone preference
Diffstat (limited to 'app/php')
-rw-r--r--app/php/facades/CalendarFacade.php17
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];
+ }
+
}
?>