@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 PhabricatorEpochExportField
4 extends PhabricatorExportField {
5
6 private $zone;
7
8 public function getTextValue($value) {
9 if ($value === null) {
10 return '';
11 }
12
13 if (!isset($this->zone)) {
14 $this->zone = new DateTimeZone('UTC');
15 }
16
17 try {
18 $date = new DateTime('@'.$value);
19 } catch (Exception $ex) {
20 return null;
21 }
22
23 $date->setTimezone($this->zone);
24 return $date->format('c');
25 }
26
27 /**
28 * @return int|null
29 */
30 public function getNaturalValue($value) {
31 if ($value === null) {
32 return $value;
33 }
34
35 return (int)$value;
36 }
37
38 public function getPHPExcelValue($value) {
39 $epoch = $this->getNaturalValue($value);
40
41 if ($epoch === null) {
42 return null;
43 }
44
45 $seconds_per_day = phutil_units('1 day in seconds');
46 $offset = ($seconds_per_day * 25569);
47
48 return ($epoch + $offset) / $seconds_per_day;
49 }
50
51 /**
52 * @phutil-external-symbol class PHPExcel_Style_NumberFormat
53 */
54 public function formatPHPExcelCell($cell, $style) {
55 $code = PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2;
56
57 $style
58 ->getNumberFormat()
59 ->setFormatCode($code);
60 }
61
62}