Combine RFC 822 and RFC 850 patterns
This commit is contained in:
parent
7ead15501b
commit
418a999ef1
2 changed files with 22 additions and 4 deletions
|
@ -8,8 +8,7 @@ namespace MensBeam\Lax;
|
||||||
|
|
||||||
class Date extends \DateTimeImmutable implements \JsonSerializable {
|
class Date extends \DateTimeImmutable implements \JsonSerializable {
|
||||||
protected const PATTERN_RFC3339 = '/^(\d{4}-\d\d-\d\d)[Tt ](\d\d:\d\d(?::\d\d(?:\.\d+)?)?)\s*([Zz]|[+\-]\d\d:?\d\d)?$/';
|
protected const PATTERN_RFC3339 = '/^(\d{4}-\d\d-\d\d)[Tt ](\d\d:\d\d(?::\d\d(?:\.\d+)?)?)\s*([Zz]|[+\-]\d\d:?\d\d)?$/';
|
||||||
protected const PATTERN_RFC822 = '/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d\d(?:\d\d)?) (\d\d:\d\d(?::\d\d(?:\.\d+)?)?)\s*([A-Z]|GMT|UTC?|[ECMP][SD]T|[+\-]\d\d:?\d\d)?$/';
|
protected const PATTERN_RFC8XX = '/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun|(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day)(?:, ?| )(?|(\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d\d(?:\d\d)?)|(\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d(?:\d\d)?)) (\d\d:\d\d(?::\d\d(?:\.\d+)?)?)\s*(?-i:([A-Z]|GMT|UTC?|[ECMP][SD]T|[+\-]\d\d:?\d\d)?)$/i';
|
||||||
protected const PATTERN_RFC850 = '/^(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day, (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d(?:\d\d)?) (\d\d:\d\d(?::\d\d(?:\.\d+)?)?)\s*([A-Z]|GMT|UTC?|[ECMP][SD]T|[+\-]\d\d:?\d\d)?$/';
|
|
||||||
protected const PATTERN_ASCTIME = '/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d\d?) (\d\d:\d\d(?::\d\d(?:\.\d+)?)?) (\d{4})$/';
|
protected const PATTERN_ASCTIME = '/^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d\d?) (\d\d:\d\d(?::\d\d(?:\.\d+)?)?) (\d{4})$/';
|
||||||
protected const INPUT_FORMAT = '!Y-m-d\TH:i:s.uO';
|
protected const INPUT_FORMAT = '!Y-m-d\TH:i:s.uO';
|
||||||
protected const MICROTIME_PRECSISION = 6;
|
protected const MICROTIME_PRECSISION = 6;
|
||||||
|
@ -106,9 +105,9 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
|
||||||
$date = $match[1];
|
$date = $match[1];
|
||||||
$time = self::parseTime($match[2]);
|
$time = self::parseTime($match[2]);
|
||||||
$zone = self::parseZone($match[3] ?? "");
|
$zone = self::parseZone($match[3] ?? "");
|
||||||
} elseif (preg_match(self::PATTERN_RFC822, $timeSpec, $match) || preg_match(self::PATTERN_RFC850, $timeSpec, $match)) {
|
} elseif (preg_match(self::PATTERN_RFC8XX, $timeSpec, $match)) {
|
||||||
$day = $match[1];
|
$day = $match[1];
|
||||||
$month = self::MONTH_MAP[$match[2]] ?? null;
|
$month = self::MONTH_MAP[ucfirst(strtolower($match[2]))] ?? null;
|
||||||
assert(!is_null($month));
|
assert(!is_null($month));
|
||||||
$year = $match[3];
|
$year = $match[3];
|
||||||
$time = self::parseTime($match[4]);
|
$time = self::parseTime($match[4]);
|
||||||
|
|
|
@ -308,3 +308,22 @@ RFC 822 with no time zone:
|
||||||
- 'Thu, 05 Mar 2020 23:08:55 -00:00'
|
- 'Thu, 05 Mar 2020 23:08:55 -00:00'
|
||||||
- 'Thu, 05 Mar 2020 23:08:55 J'
|
- 'Thu, 05 Mar 2020 23:08:55 J'
|
||||||
output: '2020-03-05T23:08:55-00:00'
|
output: '2020-03-05T23:08:55-00:00'
|
||||||
|
|
||||||
|
RFC 822 far ambiguous date:
|
||||||
|
input:
|
||||||
|
- 'Fri, 05 Mar 1999 23:08:55Z'
|
||||||
|
- 'Fri, 05 Mar 99 23:08:55Z'
|
||||||
|
output: '1999-03-05T23:08:55+00:00'
|
||||||
|
|
||||||
|
RFC 822 accepted syntax variations:
|
||||||
|
input:
|
||||||
|
- 'thu, 05 Mar 2020 23:08:55Z'
|
||||||
|
- 'tHU, 05 Mar 2020 23:08:55Z'
|
||||||
|
- 'THU, 05 Mar 2020 23:08:55Z'
|
||||||
|
- 'Thu,05 Mar 2020 23:08:55Z'
|
||||||
|
- 'Thu 05 Mar 2020 23:08:55Z'
|
||||||
|
- 'Thu, 05-Mar-2020 23:08:55Z'
|
||||||
|
- 'Thu, 05 mar 2020 23:08:55Z'
|
||||||
|
- 'Thu, 05 mAR 2020 23:08:55Z'
|
||||||
|
- 'Thu, 05 MAR 2020 23:08:55Z'
|
||||||
|
output: '2020-03-05T23:08:55+00:00'
|
||||||
|
|
Loading…
Reference in a new issue