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-03-13 18:33:31 +00:00
|
|
|
// Converts from SQLite3's date format to a specified standard date format.
|
2017-04-16 02:07:22 +00:00
|
|
|
public static function dateFormat(string $format, $date) {
|
|
|
|
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
|
|
|
$format = strtolower($format);
|
|
|
|
switch ($format) {
|
2017-04-16 02:07:22 +00:00
|
|
|
case 'unix':
|
|
|
|
return $date->getTimestamp();
|
2017-03-13 18:33:31 +00:00
|
|
|
case 'rfc822':
|
2017-04-16 02:07:22 +00:00
|
|
|
case 'http':
|
|
|
|
return $date->format(\DateTime::RFC822);
|
2017-03-13 18:33:31 +00:00
|
|
|
case 'iso8601':
|
2017-04-16 02:07:22 +00:00
|
|
|
default:
|
|
|
|
return $date->format(\DateTime::ISO8601);
|
2017-03-13 18:33:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|