2017-03-13 18:33:31 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse\Db\SQLite3;
|
2017-03-13 18:33:31 +00:00
|
|
|
|
|
|
|
class CustomFunctions {
|
2017-04-16 02:07:22 +00:00
|
|
|
protected static $tz;
|
|
|
|
|
2017-05-18 17:21:17 +00:00
|
|
|
// Converts from SQL date format to a specified standard date format.
|
2017-04-16 02:07:22 +00:00
|
|
|
public static function dateFormat(string $format, $date) {
|
2017-05-18 17:21:17 +00:00
|
|
|
$format = strtolower($format);
|
|
|
|
if($format=="sql") return $date;
|
2017-04-16 02:07:22 +00:00
|
|
|
settype($date, "string");
|
|
|
|
if($date=="") return null;
|
|
|
|
if(is_null(self::$tz)) self::$tz = new \DateTimeZone("UTC");
|
|
|
|
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $date, self::$tz);
|
2017-03-13 18:33:31 +00:00
|
|
|
switch ($format) {
|
2017-04-16 02:07:22 +00:00
|
|
|
case 'unix':
|
|
|
|
return $date->getTimestamp();
|
|
|
|
case 'http':
|
2017-05-18 17:21:17 +00:00
|
|
|
return $date->format("D, d M Y H:i:s \G\M\T");
|
2017-03-13 18:33:31 +00:00
|
|
|
case 'iso8601':
|
2017-04-16 02:07:22 +00:00
|
|
|
default:
|
2017-05-18 17:21:17 +00:00
|
|
|
return $date->format(\DateTime::ATOM);
|
2017-03-13 18:33:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|