mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Enhance getDate method to support ISO 8601 format with milliseconds and compact format with space-separated timezone
This commit is contained in:
parent
92aec968d9
commit
cb00dabd5e
1 changed files with 27 additions and 0 deletions
|
@ -99,6 +99,33 @@ class EpgParser {
|
||||||
*/
|
*/
|
||||||
public function getDate(string $date) {
|
public function getDate(string $date) {
|
||||||
$date = str_replace(' 0000', ' +0000', $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 {
|
try {
|
||||||
$dt = \DateTime::createFromFormat('YmdHis P', $date, new DateTimeZone('UTC'));
|
$dt = \DateTime::createFromFormat('YmdHis P', $date, new DateTimeZone('UTC'));
|
||||||
$dt->setTimezone(new DateTimeZone($this->targetTimeZone));
|
$dt->setTimezone(new DateTimeZone($this->targetTimeZone));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue