Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/export/field/PhabricatorEpochExportField.php
12241 views
1
<?php
2
3
final 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
public function getNaturalValue($value) {
28
if ($value === null) {
29
return $value;
30
}
31
32
return (int)$value;
33
}
34
35
public function getPHPExcelValue($value) {
36
$epoch = $this->getNaturalValue($value);
37
38
if ($epoch === null) {
39
return null;
40
}
41
42
$seconds_per_day = phutil_units('1 day in seconds');
43
$offset = ($seconds_per_day * 25569);
44
45
return ($epoch + $offset) / $seconds_per_day;
46
}
47
48
/**
49
* @phutil-external-symbol class PHPExcel_Style_NumberFormat
50
*/
51
public function formatPHPExcelCell($cell, $style) {
52
$code = PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2;
53
54
$style
55
->getNumberFormat()
56
->setFormatCode($code);
57
}
58
59
}
60
61