Skip to content

Commit

Permalink
Additional timestamp format added #392
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Jun 23, 2023
1 parent 8ff2782 commit 4bbcb4b
Show file tree
Hide file tree
Showing 3 changed files with 7 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
- NaN
- Additional timestamp format added #392 (thanks @esk-ap)

### Breaking changes
- NaN
Expand Down
5 changes: 5 additions & 0 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@ private function parseDate(object $header): void {
array_splice($parts, -2);
$date = implode(' ', $parts);
break;
case preg_match('/([A-Z]{2,4}\,\ [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:
$array = explode(',', $date);
array_shift($array);
$date = Carbon::createFromFormat("d M Y H:i:s O", trim(implode(',', $array)));
break;
case preg_match('/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ UT)+$/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}\ UT)+$/i', $date) > 0:
$date .= 'C';
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/DateTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DateTemplateTest extends FixtureTestCase {
"14 Sep 2019 00:10:08 UT +0200" => "2019-09-14 00:10:08",
"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",
];

/**
Expand Down

0 comments on commit 4bbcb4b

Please sign in to comment.