summaryrefslogtreecommitdiffstats
path: root/SchedulerHelperDate.php
diff options
context:
space:
mode:
authorAlexKlimenkov <shurick.klimenkov@gmail.com>2016-03-24 16:06:52 +0300
committerAlexKlimenkov <shurick.klimenkov@gmail.com>2016-03-24 16:06:52 +0300
commit3302a00e737f2039f4fb4075d21e5d597bdeff24 (patch)
treefb351f77aebbfc2b2036ffd6b8d2022665c4c14d /SchedulerHelperDate.php
parent2aebc0fb22e7502bbf610e7ffcf655ddd77fefae (diff)
parent551d156dd610c2ab5b79a99f08d9a73856004ffb (diff)
downloadscheduler-helper-php-3302a00e737f2039f4fb4075d21e5d597bdeff24.zip
scheduler-helper-php-3302a00e737f2039f4fb4075d21e5d597bdeff24.tar.gz
scheduler-helper-php-3302a00e737f2039f4fb4075d21e5d597bdeff24.tar.bz2
Merge pull request #21 from mperednya/master
Fix recurrings detection.
Diffstat (limited to 'SchedulerHelperDate.php')
-rwxr-xr-xSchedulerHelperDate.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/SchedulerHelperDate.php b/SchedulerHelperDate.php
index b664492..33635a9 100755
--- a/SchedulerHelperDate.php
+++ b/SchedulerHelperDate.php
@@ -77,6 +77,14 @@ class SchedulerHelperDate
return $timestamp;
}
+ static public function getTimestampFromUTCTimestamp($stamp, $serverDate){
+ $date = new DateTime();
+ $date->setTimezone(new \DateTimeZone("UTC"));
+ $date->setTimestamp($stamp);
+ $date = self::getDateTimestamp($date->format(self::FORMAT_DEFAULT), $serverDate);
+ return $date;
+ }
+
static public function getDayOfWeek($timestamp) {
$weekDay = getdate($timestamp)["wday"];
return $weekDay;
@@ -110,4 +118,34 @@ class SchedulerHelperDate
return self::addDate($timestamp, self::$INTERVAL_UNITS["year"], $count);
}
+ static public function weekStart($timestamp, $startOnMonday = true){
+ $shift = self::getDayOfWeek($timestamp);
+ if($startOnMonday){
+ if($shift === 0){
+ $shift = 6;
+ }
+ else{
+ $shift--;
+ }
+ }
+ return self::addDays($timestamp, -1*$shift);
+ }
+
+ static public function monthStart($timestamp){
+ $date = new DateTime();
+ $date->setTimestamp($timestamp);
+ $m = $date->format('m');
+ $y = $date->format('Y');
+ $date->setDate($y, $m, 1);
+ return $date->getTimestamp();
+ }
+
+ static public function yearStart($timestamp){
+ $date = new DateTime();
+ $date->setTimestamp($timestamp);
+ $y = $date->format('Y');
+ $date->setDate($y, 1, 1);
+ return $date->getTimestamp();
+ }
+
} \ No newline at end of file