Changeset View
Changeset View
Standalone View
Standalone View
src/view/form/control/AphrontFormDateControlValue.php
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | private function getFormattedDateFromDate($date, $time) { | ||||
} | } | ||||
return array( | return array( | ||||
$datetime->format($this->getDateFormat()), | $datetime->format($this->getDateFormat()), | ||||
$datetime->format($this->getTimeFormat()), | $datetime->format($this->getTimeFormat()), | ||||
); | ); | ||||
} | } | ||||
/** | |||||
* Create a DateTime object including timezone | |||||
* @param string $date Date, like "2024-08-20" or "2024-07-1" or such | |||||
* @param string|null $time Time, like "12:00 AM" or such | |||||
* @return DateTime|null | |||||
*/ | |||||
private function newDateTime($date, $time) { | private function newDateTime($date, $time) { | ||||
$date = $this->getStandardDateFormat($date); | $date = $this->getStandardDateFormat($date); | ||||
$time = $this->getStandardTimeFormat($time); | $time = $this->getStandardTimeFormat($time); | ||||
try { | try { | ||||
// We need to provide the timezone in the constructor, and also set it | // We need to provide the timezone in the constructor, and also set it | ||||
// explicitly. If the date is an epoch timestamp, the timezone in the | // explicitly. If the date is an epoch timestamp, the timezone in the | ||||
// constructor is ignored. If the date is not an epoch timestamp, it is | // constructor is ignored. If the date is not an epoch timestamp, it is | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | private function getFormatSeparator() { | ||||
switch ($format) { | switch ($format) { | ||||
case 'n/j/Y': | case 'n/j/Y': | ||||
return '/'; | return '/'; | ||||
default: | default: | ||||
return '-'; | return '-'; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @return DateTime|null | |||||
*/ | |||||
public function getDateTime() { | public function getDateTime() { | ||||
return $this->newDateTime($this->valueDate, $this->valueTime); | return $this->newDateTime($this->valueDate, $this->valueTime); | ||||
} | } | ||||
/** | |||||
* @return DateTimeZone | |||||
*/ | |||||
private function getTimezone() { | private function getTimezone() { | ||||
if ($this->zone) { | if ($this->zone) { | ||||
return $this->zone; | return $this->zone; | ||||
} | } | ||||
$viewer_zone = $this->viewer->getTimezoneIdentifier(); | $viewer_zone = $this->viewer->getTimezoneIdentifier(); | ||||
$this->zone = new DateTimeZone($viewer_zone); | $this->zone = new DateTimeZone($viewer_zone); | ||||
return $this->zone; | return $this->zone; | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0