Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/export/field/PhabricatorEpochExportField.php
| <?php | <?php | ||||
| final class PhabricatorEpochExportField | final class PhabricatorEpochExportField | ||||
| extends PhabricatorExportField { | extends PhabricatorExportField { | ||||
| private $zone; | private $zone; | ||||
| public function getTextValue($value) { | public function getTextValue($value) { | ||||
| if ($value === null) { | |||||
| return ''; | |||||
| } | |||||
| if (!isset($this->zone)) { | if (!isset($this->zone)) { | ||||
| $this->zone = new DateTimeZone('UTC'); | $this->zone = new DateTimeZone('UTC'); | ||||
| } | } | ||||
| try { | try { | ||||
| $date = new DateTime('@'.$value); | $date = new DateTime('@'.$value); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $date->setTimezone($this->zone); | $date->setTimezone($this->zone); | ||||
| return $date->format('c'); | return $date->format('c'); | ||||
| } | } | ||||
| public function getNaturalValue($value) { | public function getNaturalValue($value) { | ||||
| if ($value === null) { | |||||
| return $value; | |||||
| } | |||||
| return (int)$value; | return (int)$value; | ||||
| } | } | ||||
| public function getPHPExcelValue($value) { | public function getPHPExcelValue($value) { | ||||
| $epoch = $this->getNaturalValue($value); | $epoch = $this->getNaturalValue($value); | ||||
| if ($epoch === null) { | |||||
| return null; | |||||
| } | |||||
| $seconds_per_day = phutil_units('1 day in seconds'); | $seconds_per_day = phutil_units('1 day in seconds'); | ||||
| $offset = ($seconds_per_day * 25569); | $offset = ($seconds_per_day * 25569); | ||||
| return ($epoch + $offset) / $seconds_per_day; | return ($epoch + $offset) / $seconds_per_day; | ||||
| } | } | ||||
| /** | /** | ||||
| * @phutil-external-symbol class PHPExcel_Style_NumberFormat | * @phutil-external-symbol class PHPExcel_Style_NumberFormat | ||||
| Show All 10 Lines | |||||