v26.6.0 updates

This commit is contained in:
Thilina Hasantha
2019-07-26 03:53:24 +02:00
parent c3344b99fa
commit fd99ea299e
195 changed files with 18838 additions and 2639 deletions

View File

@@ -21,4 +21,43 @@ class Timezone extends BaseModel
{
return array("get","element");
}
public function getTimezonesWithOffset()
{
$tz = new Timezone();
$tzs = $tz->Find("1 = 1");
$modifiedTimeZones = [];
foreach ($tzs as $tz) {
try {
$z = new \DateTimeZone($tz->name);
$c = new \DateTime(null, $z);
$tz->details = sprintf("(%s) %s", $this->formatOffset($z->getOffset($c)), $tz->name);
$modifiedTimeZones[] = $tz;
} catch (\Exception $e) {
}
}
usort($modifiedTimeZones, function ($a, $b) { return strcmp($a->details, $b->details); });
return $modifiedTimeZones;
}
public function formatOffset($offset) {
$hours = $offset / 3600;
$remainder = $offset % 3600;
$sign = $hours > 0 ? '+' : '-';
$hour = (int) abs($hours);
$minutes = (int) abs($remainder / 60);
if ($hour == 0 AND $minutes == 0) {
$sign = ' ';
}
return 'GMT' . $sign . str_pad($hour, 2, '0', STR_PAD_LEFT)
.':'. str_pad($minutes,2, '0');
}
public function fieldValueMethods()
{
return ['getTimezonesWithOffset'];
}
}