@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 54 lines 1.4 kB view raw
1<?php 2 3abstract class PhutilCalendarDateTime 4 extends Phobject { 5 6 private $viewerTimezone; 7 private $isAllDay = false; 8 9 public function setViewerTimezone($viewer_timezone) { 10 $this->viewerTimezone = $viewer_timezone; 11 return $this; 12 } 13 14 public function getViewerTimezone() { 15 return $this->viewerTimezone; 16 } 17 18 public function setIsAllDay($is_all_day) { 19 $this->isAllDay = $is_all_day; 20 return $this; 21 } 22 23 public function getIsAllDay() { 24 return $this->isAllDay; 25 } 26 27 public function getEpoch() { 28 $datetime = $this->newPHPDateTime(); 29 return (int)$datetime->format('U'); 30 } 31 32 public function getISO8601() { 33 $datetime = $this->newPHPDateTime(); 34 35 if ($this->getIsAllDay()) { 36 return $datetime->format('Ymd'); 37 } else if ($this->getTimezone()) { 38 // With a timezone, the event occurs at a specific second universally. 39 // We return the UTC representation of that point in time. 40 $datetime->setTimezone(new DateTimeZone('UTC')); 41 return $datetime->format('Ymd\\THis\\Z'); 42 } else { 43 // With no timezone, events are "floating" and occur at local time. 44 // We return a representation without the "Z". 45 return $datetime->format('Ymd\\THis'); 46 } 47 } 48 49 abstract public function newPHPDateTimeZone(); 50 abstract public function newPHPDateTime(); 51 abstract public function newAbsoluteDateTime(); 52 53 abstract public function getTimezone(); 54}