Yet more date tests
This commit is contained in:
parent
b9fa795b88
commit
a1421b3008
2 changed files with 298 additions and 25 deletions
18
lib/Date.php
18
lib/Date.php
|
@ -106,7 +106,7 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
|
|||
$date = $match[1];
|
||||
$time = self::parseTime($match[2]);
|
||||
$zone = self::parseZone($match[3] ?? "");
|
||||
} elseif (preg_match(self::PATTERN_RFC822, $timeSpec, $match)) {
|
||||
} elseif (preg_match(self::PATTERN_RFC822, $timeSpec, $match) || preg_match(self::PATTERN_RFC850, $timeSpec, $match)) {
|
||||
$day = $match[1];
|
||||
$month = self::MONTH_MAP[$match[2]] ?? null;
|
||||
assert(!is_null($month));
|
||||
|
@ -116,21 +116,7 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
|
|||
if (strlen($year) === 2) {
|
||||
$ambiguousCentury = true;
|
||||
// get the current century
|
||||
$century = intdiv((int) $now->format("Y"), 100);
|
||||
$year = (string) ($century + (int) $year);
|
||||
}
|
||||
$date = "$year-$month-$day";
|
||||
} elseif (preg_match(self::PATTERN_RFC850, $timeSpec, $match)) {
|
||||
$day = $match[1];
|
||||
$month = self::MONTH_MAP[$match[2]] ?? null;
|
||||
assert(!is_null($month));
|
||||
$year = $match[3];
|
||||
$time = self::parseTime($match[4]);
|
||||
$zone = self::parseZone($match[5] ?? "");
|
||||
if (strlen($year) === 2) {
|
||||
$ambiguousCentury = true;
|
||||
// get the current century
|
||||
$century = intdiv((int) $now->format("Y"), 100);
|
||||
$century = intdiv((int) $now->format("Y"), 100) * 100;
|
||||
$year = (string) ($century + (int) $year);
|
||||
}
|
||||
$date = "$year-$month-$day";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
RFC 3339 Zulu time:
|
||||
input:
|
||||
input:
|
||||
- '2020-03-05T23:08:55Z'
|
||||
- '2020-03-05T23:08:55z'
|
||||
- '2020-03-05t23:08:55Z'
|
||||
|
@ -9,7 +9,7 @@ RFC 3339 Zulu time:
|
|||
output: '2020-03-05T23:08:55+00:00'
|
||||
|
||||
RFC 3339 UTC-4:
|
||||
input:
|
||||
input:
|
||||
- '2020-03-05T23:08:55-0400'
|
||||
- '2020-03-05t23:08:55-0400'
|
||||
- '2020-03-05 23:08:55-0400'
|
||||
|
@ -25,7 +25,7 @@ RFC 3339 UTC-4:
|
|||
output: '2020-03-05T23:08:55-04:00'
|
||||
|
||||
RFC 3339 UTC+11:
|
||||
input:
|
||||
input:
|
||||
- '2020-03-05T23:08:55+1100'
|
||||
- '2020-03-05t23:08:55+1100'
|
||||
- '2020-03-05 23:08:55+1100'
|
||||
|
@ -41,7 +41,7 @@ RFC 3339 UTC+11:
|
|||
output: '2020-03-05T23:08:55+11:00'
|
||||
|
||||
RFC 3339 with various precision:
|
||||
input:
|
||||
input:
|
||||
- '2020-03-05T23:08:00Z'
|
||||
- '2020-03-05T23:08Z'
|
||||
- '2020-03-05T23:08:00.0Z'
|
||||
|
@ -71,7 +71,7 @@ RFC 3339 with subseconds:
|
|||
output: '2020-03-05T23:08:00.123456+00:00'
|
||||
|
||||
RFC 3339 without timezone:
|
||||
input:
|
||||
input:
|
||||
- '2020-03-05T23:08:55-0000'
|
||||
- '2020-03-05T23:08:55-00:00'
|
||||
- '2020-03-05T23:08:55 -0000'
|
||||
|
@ -90,7 +90,7 @@ RFC 3339 without timezone:
|
|||
output: '2020-03-05T23:08:55-00:00'
|
||||
|
||||
RFC 3339 with invalid data:
|
||||
input:
|
||||
input:
|
||||
- '2020-02-31T23:08:55Z' # impossible date (February 31)
|
||||
- '2020-02-28T25:08:55Z' # impossible hour
|
||||
- '2020-02-28T23:65:55Z' # impossible minute
|
||||
|
@ -102,7 +102,7 @@ RFC 3339 with invalid data:
|
|||
output: null
|
||||
|
||||
RFC 3339 with invalid syntax:
|
||||
input:
|
||||
input:
|
||||
- '20-02-05T23:08:55Z'
|
||||
- '2020-2-05T23:08:55Z'
|
||||
- '2020-02-5T23:08:55Z'
|
||||
|
@ -115,7 +115,294 @@ RFC 3339 with invalid syntax:
|
|||
output: null
|
||||
|
||||
RFC 822 Zulu time:
|
||||
input:
|
||||
input:
|
||||
- 'Thu, 05 Mar 2020 23:08:55Z'
|
||||
#- 'Thu, 05 Mar 20 23:08:55Z'
|
||||
- 'Thu, 05 Mar 20 23:08:55Z'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 Z'
|
||||
- 'Thu, 05 Mar 20 23:08:55 Z'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 GMT'
|
||||
- 'Thu, 05 Mar 20 23:08:55 GMT'
|
||||
- 'Thu, 05 Mar 2020 23:08:55GMT'
|
||||
- 'Thu, 05 Mar 20 23:08:55GMT'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 UTC'
|
||||
- 'Thu, 05 Mar 20 23:08:55 UTC'
|
||||
- 'Thu, 05 Mar 2020 23:08:55UTC'
|
||||
- 'Thu, 05 Mar 20 23:08:55UTC'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 UT'
|
||||
- 'Thu, 05 Mar 20 23:08:55 UT'
|
||||
- 'Thu, 05 Mar 2020 23:08:55UT'
|
||||
- 'Thu, 05 Mar 20 23:08:55UT'
|
||||
- 'Mon, 05 Mar 2020 23:08:55Z'
|
||||
- 'Tue, 05 Mar 2020 23:08:55Z'
|
||||
- 'Wed, 05 Mar 2020 23:08:55Z'
|
||||
- 'Fri, 05 Mar 2020 23:08:55Z'
|
||||
- 'Sat, 05 Mar 2020 23:08:55Z'
|
||||
- 'Sun, 05 Mar 2020 23:08:55Z'
|
||||
output: '2020-03-05T23:08:55+00:00'
|
||||
|
||||
RFC 822 UTC+1:
|
||||
input:
|
||||
- 'Sun, 05 Jan 2020 23:08:55A'
|
||||
- 'Sun, 05 Jan 2020 23:08:55+0100'
|
||||
- 'Sun, 05 Jan 2020 23:08:55+01:00'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 A'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 +0100'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 +01:00'
|
||||
output: '2020-01-05T23:08:55+01:00'
|
||||
|
||||
RFC 822 UTC+2:
|
||||
input:
|
||||
- 'Wed, 05 Feb 2020 23:08:55B'
|
||||
- 'Wed, 05 Feb 2020 23:08:55+0200'
|
||||
- 'Wed, 05 Feb 2020 23:08:55+02:00'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 B'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 +0200'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 +02:00'
|
||||
output: '2020-02-05T23:08:55+02:00'
|
||||
|
||||
RFC 822 UTC+3:
|
||||
input:
|
||||
- 'Thu, 05 Mar 2020 23:08:55C'
|
||||
- 'Thu, 05 Mar 2020 23:08:55+0300'
|
||||
- 'Thu, 05 Mar 2020 23:08:55+03:00'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 C'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 +0300'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 +03:00'
|
||||
output: '2020-03-05T23:08:55+03:00'
|
||||
|
||||
RFC 822 UTC+4:
|
||||
input:
|
||||
- 'Sun, 05 Apr 2020 23:08:55D'
|
||||
- 'Sun, 05 Apr 2020 23:08:55+0400'
|
||||
- 'Sun, 05 Apr 2020 23:08:55+04:00'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 D'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 +0400'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 +04:00'
|
||||
output: '2020-04-05T23:08:55+04:00'
|
||||
|
||||
RFC 822 UTC+5:
|
||||
input:
|
||||
- 'Tue, 05 May 2020 23:08:55E'
|
||||
- 'Tue, 05 May 2020 23:08:55+0500'
|
||||
- 'Tue, 05 May 2020 23:08:55+05:00'
|
||||
- 'Tue, 05 May 2020 23:08:55 E'
|
||||
- 'Tue, 05 May 2020 23:08:55 +0500'
|
||||
- 'Tue, 05 May 2020 23:08:55 +05:00'
|
||||
output: '2020-05-05T23:08:55+05:00'
|
||||
|
||||
RFC 822 UTC+6:
|
||||
input:
|
||||
- 'Fri, 05 Jun 2020 23:08:55F'
|
||||
- 'Fri, 05 Jun 2020 23:08:55+0600'
|
||||
- 'Fri, 05 Jun 2020 23:08:55+06:00'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 F'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 +0600'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 +06:00'
|
||||
output: '2020-06-05T23:08:55+06:00'
|
||||
|
||||
RFC 822 UTC+7:
|
||||
input:
|
||||
- 'Sun, 05 Jul 2020 23:08:55G'
|
||||
- 'Sun, 05 Jul 2020 23:08:55+0700'
|
||||
- 'Sun, 05 Jul 2020 23:08:55+07:00'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 G'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 +0700'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 +07:00'
|
||||
output: '2020-07-05T23:08:55+07:00'
|
||||
|
||||
RFC 822 UTC+8:
|
||||
input:
|
||||
- 'Wed, 05 Aug 2020 23:08:55H'
|
||||
- 'Wed, 05 Aug 2020 23:08:55+0800'
|
||||
- 'Wed, 05 Aug 2020 23:08:55+08:00'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 H'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 +0800'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 +08:00'
|
||||
output: '2020-08-05T23:08:55+08:00'
|
||||
|
||||
RFC 822 UTC+9:
|
||||
input:
|
||||
- 'Sat, 05 Sep 2020 23:08:55I'
|
||||
- 'Sat, 05 Sep 2020 23:08:55+0900'
|
||||
- 'Sat, 05 Sep 2020 23:08:55+09:00'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 I'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 +0900'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 +09:00'
|
||||
output: '2020-09-05T23:08:55+09:00'
|
||||
|
||||
RFC 822 UTC+10:
|
||||
input:
|
||||
- 'Mon, 05 Oct 2020 23:08:55K'
|
||||
- 'Mon, 05 Oct 2020 23:08:55+1000'
|
||||
- 'Mon, 05 Oct 2020 23:08:55+10:00'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 K'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 +1000'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 +10:00'
|
||||
output: '2020-10-05T23:08:55+10:00'
|
||||
|
||||
RFC 822 UTC+11:
|
||||
input:
|
||||
- 'Thu, 05 Nov 2020 23:08:55L'
|
||||
- 'Thu, 05 Nov 2020 23:08:55+1100'
|
||||
- 'Thu, 05 Nov 2020 23:08:55+11:00'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 L'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 +1100'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 +11:00'
|
||||
output: '2020-11-05T23:08:55+11:00'
|
||||
|
||||
RFC 822 UTC+12:
|
||||
input:
|
||||
- 'Sat, 05 Dec 2020 23:08:55M'
|
||||
- 'Sat, 05 Dec 2020 23:08:55+1200'
|
||||
- 'Sat, 05 Dec 2020 23:08:55+12:00'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 M'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 +1200'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 +12:00'
|
||||
output: '2020-12-05T23:08:55+12:00'
|
||||
|
||||
RFC 822 UTC-1:
|
||||
input:
|
||||
- 'Sun, 05 Jan 2020 23:08:55N'
|
||||
- 'Sun, 05 Jan 2020 23:08:55-0100'
|
||||
- 'Sun, 05 Jan 2020 23:08:55-01:00'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 N'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 -0100'
|
||||
- 'Sun, 05 Jan 2020 23:08:55 -01:00'
|
||||
output: '2020-01-05T23:08:55-01:00'
|
||||
|
||||
RFC 822 UTC-2:
|
||||
input:
|
||||
- 'Wed, 05 Feb 2020 23:08:55O'
|
||||
- 'Wed, 05 Feb 2020 23:08:55-0200'
|
||||
- 'Wed, 05 Feb 2020 23:08:55-02:00'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 O'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 -0200'
|
||||
- 'Wed, 05 Feb 2020 23:08:55 -02:00'
|
||||
output: '2020-02-05T23:08:55-02:00'
|
||||
|
||||
RFC 822 UTC-3:
|
||||
input:
|
||||
- 'Thu, 05 Mar 2020 23:08:55P'
|
||||
- 'Thu, 05 Mar 2020 23:08:55-0300'
|
||||
- 'Thu, 05 Mar 2020 23:08:55-03:00'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 P'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 -0300'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 -03:00'
|
||||
output: '2020-03-05T23:08:55-03:00'
|
||||
|
||||
RFC 822 UTC-4:
|
||||
input:
|
||||
- 'Sun, 05 Apr 2020 23:08:55Q'
|
||||
- 'Sun, 05 Apr 2020 23:08:55-0400'
|
||||
- 'Sun, 05 Apr 2020 23:08:55-04:00'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 Q'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 -0400'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 -04:00'
|
||||
- 'Sun, 05 Apr 2020 23:08:55EDT'
|
||||
- 'Sun, 05 Apr 2020 23:08:55 EDT'
|
||||
output: '2020-04-05T23:08:55-04:00'
|
||||
|
||||
RFC 822 UTC-5:
|
||||
input:
|
||||
- 'Tue, 05 May 2020 23:08:55R'
|
||||
- 'Tue, 05 May 2020 23:08:55-0500'
|
||||
- 'Tue, 05 May 2020 23:08:55-05:00'
|
||||
- 'Tue, 05 May 2020 23:08:55 R'
|
||||
- 'Tue, 05 May 2020 23:08:55 -0500'
|
||||
- 'Tue, 05 May 2020 23:08:55 -05:00'
|
||||
- 'Tue, 05 May 2020 23:08:55CDT'
|
||||
- 'Tue, 05 May 2020 23:08:55EST'
|
||||
- 'Tue, 05 May 2020 23:08:55 CDT'
|
||||
- 'Tue, 05 May 2020 23:08:55 EST'
|
||||
output: '2020-05-05T23:08:55-05:00'
|
||||
|
||||
RFC 822 UTC-6:
|
||||
input:
|
||||
- 'Fri, 05 Jun 2020 23:08:55S'
|
||||
- 'Fri, 05 Jun 2020 23:08:55-0600'
|
||||
- 'Fri, 05 Jun 2020 23:08:55-06:00'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 S'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 -0600'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 -06:00'
|
||||
- 'Fri, 05 Jun 2020 23:08:55MDT'
|
||||
- 'Fri, 05 Jun 2020 23:08:55CST'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 MDT'
|
||||
- 'Fri, 05 Jun 2020 23:08:55 CST'
|
||||
output: '2020-06-05T23:08:55-06:00'
|
||||
|
||||
RFC 822 UTC-7:
|
||||
input:
|
||||
- 'Sun, 05 Jul 2020 23:08:55T'
|
||||
- 'Sun, 05 Jul 2020 23:08:55-0700'
|
||||
- 'Sun, 05 Jul 2020 23:08:55-07:00'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 T'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 -0700'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 -07:00'
|
||||
- 'Sun, 05 Jul 2020 23:08:55PDT'
|
||||
- 'Sun, 05 Jul 2020 23:08:55MST'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 PDT'
|
||||
- 'Sun, 05 Jul 2020 23:08:55 MST'
|
||||
output: '2020-07-05T23:08:55-07:00'
|
||||
|
||||
RFC 822 UTC-8:
|
||||
input:
|
||||
- 'Wed, 05 Aug 2020 23:08:55U'
|
||||
- 'Wed, 05 Aug 2020 23:08:55-0800'
|
||||
- 'Wed, 05 Aug 2020 23:08:55-08:00'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 U'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 -0800'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 -08:00'
|
||||
- 'Wed, 05 Aug 2020 23:08:55PST'
|
||||
- 'Wed, 05 Aug 2020 23:08:55 PST'
|
||||
output: '2020-08-05T23:08:55-08:00'
|
||||
|
||||
RFC 822 UTC-9:
|
||||
input:
|
||||
- 'Sat, 05 Sep 2020 23:08:55V'
|
||||
- 'Sat, 05 Sep 2020 23:08:55-0900'
|
||||
- 'Sat, 05 Sep 2020 23:08:55-09:00'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 V'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 -0900'
|
||||
- 'Sat, 05 Sep 2020 23:08:55 -09:00'
|
||||
output: '2020-09-05T23:08:55-09:00'
|
||||
|
||||
RFC 822 UTC-10:
|
||||
input:
|
||||
- 'Mon, 05 Oct 2020 23:08:55W'
|
||||
- 'Mon, 05 Oct 2020 23:08:55-1000'
|
||||
- 'Mon, 05 Oct 2020 23:08:55-10:00'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 W'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 -1000'
|
||||
- 'Mon, 05 Oct 2020 23:08:55 -10:00'
|
||||
output: '2020-10-05T23:08:55-10:00'
|
||||
|
||||
RFC 822 UTC-11:
|
||||
input:
|
||||
- 'Thu, 05 Nov 2020 23:08:55X'
|
||||
- 'Thu, 05 Nov 2020 23:08:55-1100'
|
||||
- 'Thu, 05 Nov 2020 23:08:55-11:00'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 X'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 -1100'
|
||||
- 'Thu, 05 Nov 2020 23:08:55 -11:00'
|
||||
output: '2020-11-05T23:08:55-11:00'
|
||||
|
||||
RFC 822 UTC-12:
|
||||
input:
|
||||
- 'Sat, 05 Dec 2020 23:08:55Y'
|
||||
- 'Sat, 05 Dec 2020 23:08:55-1200'
|
||||
- 'Sat, 05 Dec 2020 23:08:55-12:00'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 Y'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 -1200'
|
||||
- 'Sat, 05 Dec 2020 23:08:55 -12:00'
|
||||
output: '2020-12-05T23:08:55-12:00'
|
||||
|
||||
RFC 822 with no time zone:
|
||||
input:
|
||||
- 'Thu, 05 Mar 2020 23:08:55'
|
||||
- 'Thu, 05 Mar 2020 23:08:55-0000'
|
||||
- 'Thu, 05 Mar 2020 23:08:55-00:00'
|
||||
- 'Thu, 05 Mar 2020 23:08:55J'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 -0000'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 -00:00'
|
||||
- 'Thu, 05 Mar 2020 23:08:55 J'
|
||||
output: '2020-03-05T23:08:55-00:00'
|
||||
|
|
Loading…
Reference in a new issue