Skip to content

Commit

Permalink
Additional timestamp formats added #198
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Jun 23, 2023
1 parent dc237ef commit d8880df
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Catching and handling iconv decoding exception #397

### Added
- Additional timestamp format added #392 (thanks @esk-ap)
- Additional timestamp formats added #198 #392 (thanks @esk-ap)

### Breaking changes
- NaN
Expand Down
21 changes: 21 additions & 0 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,27 @@ private function parseDate(object $header): void {
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}[\,]\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4})+$/i', $date) > 0:
$date = str_replace(',', '', $date);
break;
// match case for: Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)/Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)
case preg_match('/([A-Z]{2,3}\.\,\ [0-9]{1,2}\ [A-Z]{2,3}\.\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \([A-Z]{3,4}\))\/([A-Z]{2,3}\.\,\ [0-9]{1,2}\ [A-Z]{2,3}\.\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \([A-Z]{3,4}\))+$/i', $date) > 0:
$dates = explode('/', $date);
$date = array_shift($dates);
$array = explode(',', $date);
array_shift($array);
$date = trim(implode(',', $array));
$array = explode(' ', $date);
array_pop($array);
$date = trim(implode(' ', $array));
$date = Carbon::createFromFormat("d M. Y H:i:s O", $date);
break;
// match case for: fr., 25 nov. 2022 06:27:14 +0100/fr., 25 nov. 2022 06:27:14 +0100
case preg_match('/([A-Z]{2,3}\.\,\ [0-9]{1,2}\ [A-Z]{2,3}\.\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4})\/([A-Z]{2,3}\.\,\ [0-9]{1,2}\ [A-Z]{2,3}\.\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4})+$/i', $date) > 0:
$dates = explode('/', $date);
$date = array_shift($dates);
$array = explode(',', $date);
array_shift($array);
$date = trim(implode(',', $array));
$date = Carbon::createFromFormat("d M. Y H:i:s O", $date);
break;
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ \+[0-9]{2,4}\ \(\+[0-9]{1,2}\))+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}[\,|\ \,]\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}.*)+$/i', $date) > 0:
case preg_match('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i', $date) > 0:
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/DateTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class DateTemplateTest extends FixtureTestCase {
"Tue, 08 Nov 2022 18:47:20 +0000 14:03:33 +0000" => "2022-11-08 18:47:20",
"Sat, 10, Dec 2022 09:35:19 +0100" => "2022-12-10 08:35:19",
"Thur, 16 Mar 2023 15:33:07 +0400" => "2023-03-16 11:33:07",
"fr., 25 nov. 2022 06:27:14 +0100/fr., 25 nov. 2022 06:27:14 +0100" => "2022-11-25 05:27:14",
"Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)/Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)" => "2022-02-15 05:52:44",
];

/**
Expand Down

0 comments on commit d8880df

Please sign in to comment.