1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

Enhance getDate method to support ISO 8601 format with milliseconds and compact format with space-separated timezone

This commit is contained in:
Daniel Neto 2025-09-24 18:58:37 -03:00
parent 92aec968d9
commit cb00dabd5e

View file

@ -99,6 +99,33 @@ class EpgParser {
*/
public function getDate(string $date) {
$date = str_replace(' 0000', ' +0000', $date);
// Handle ISO 8601 format with milliseconds: "2025-09-22T00:00:00.000 +0000"
try {
$dt = \DateTime::createFromFormat('Y-m-d\TH:i:s.u P', $date, new DateTimeZone('UTC'));
if ($dt !== false) {
$dt->setTimezone(new DateTimeZone($this->targetTimeZone));
return $dt->format('Y-m-d H:i:s');
}
} catch (\Exception $e) {
} catch (\Error $e) {
}
// Handle compact format with space-separated timezone: "20250924004920 0000"
try {
$dt = \DateTime::createFromFormat('YmdHis O', $date, new DateTimeZone('UTC'));
if ($dt !== false) {
$dt->setTimezone(new DateTimeZone($this->targetTimeZone));
return $dt->format('Y-m-d H:i:s');
}
} catch (\Exception $e) {
} catch (\Error $e) {
}
try {
$dt = \DateTime::createFromFormat('YmdHis P', $date, new DateTimeZone('UTC'));
$dt->setTimezone(new DateTimeZone($this->targetTimeZone));