summaryrefslogtreecommitdiffstats
path: root/SchedulerHelperDate.php
diff options
context:
space:
mode:
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