@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
1<?php
2
3final class PhutilCalendarRelativeDateTime
4 extends PhutilCalendarProxyDateTime {
5
6 private $duration;
7
8 public function setOrigin(PhutilCalendarDateTime $origin) {
9 return $this->setProxy($origin);
10 }
11
12 public function getOrigin() {
13 return $this->getProxy();
14 }
15
16 public function setDuration(PhutilCalendarDuration $duration) {
17 $this->duration = $duration;
18 return $this;
19 }
20
21 public function getDuration() {
22 return $this->duration;
23 }
24
25 public function newPHPDateTime() {
26 $datetime = parent::newPHPDateTime();
27 $duration = $this->getDuration();
28
29 if ($duration->getIsNegative()) {
30 $sign = '-';
31 } else {
32 $sign = '+';
33 }
34
35 $map = array(
36 'weeks' => $duration->getWeeks(),
37 'days' => $duration->getDays(),
38 'hours' => $duration->getHours(),
39 'minutes' => $duration->getMinutes(),
40 'seconds' => $duration->getSeconds(),
41 );
42
43 foreach ($map as $unit => $value) {
44 if (!$value) {
45 continue;
46 }
47 $datetime->modify("{$sign}{$value} {$unit}");
48 }
49
50 return $datetime;
51 }
52
53 public function newAbsoluteDateTime() {
54 $clone = clone $this;
55
56 if ($clone->getTimezone()) {
57 $clone->setViewerTimezone(null);
58 }
59
60 $datetime = $clone->newPHPDateTime();
61
62 return id(new PhutilCalendarAbsoluteDateTime())
63 ->setYear((int)$datetime->format('Y'))
64 ->setMonth((int)$datetime->format('m'))
65 ->setDay((int)$datetime->format('d'))
66 ->setHour((int)$datetime->format('H'))
67 ->setMinute((int)$datetime->format('i'))
68 ->setSecond((int)$datetime->format('s'))
69 ->setIsAllDay($clone->getIsAllDay())
70 ->setTimezone($clone->getTimezone())
71 ->setViewerTimezone($this->getViewerTimezone());
72 }
73
74}