1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 17:12:41 +00:00
Arsse/lib/Db/SQLite3/CustomFunctions.php
J. King 0bc2841837 Last of subscription tests
- Also tweaked SQL dateformat() function to output proper HTTP dates
- Also introduced method to set a default output date format
2017-05-18 13:21:17 -04:00

26 lines
No EOL
867 B
PHP

<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\Db\SQLite3;
class CustomFunctions {
protected static $tz;
// Converts from SQL date format to a specified standard date format.
public static function dateFormat(string $format, $date) {
$format = strtolower($format);
if($format=="sql") return $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);
switch ($format) {
case 'unix':
return $date->getTimestamp();
case 'http':
return $date->format("D, d M Y H:i:s \G\M\T");
case 'iso8601':
default:
return $date->format(\DateTime::ATOM);
}
}
}