Last active
April 2, 2020 06:20
-
-
Save bmcminn/9748b9df0a632a06d9fe780179ab2f57 to your computer and use it in GitHub Desktop.
Testing date parsing in regards to leap year 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Test Date Parsing</title> | |
</head> | |
<body> | |
<?php | |
function parseTimeString($date = null, $format = null) { | |
$d = new DateTime(); | |
if ($date && $format) { | |
$d = DateTime::createFromFormat($format, $date); | |
} | |
return $d->getTimestamp() * 1000; | |
} | |
$dates = [ | |
'today raw' => parseTimeString(), | |
'today fixed' => parseTimeString('2020-04-01', 'Y-m-d'), | |
'd1' => parseTimeString('2020-03-31', 'Y-m-d'), | |
'd2' => parseTimeString('31-03-2020', 'd-m-Y'), | |
'd3' => parseTimeString('31/03/2020', 'd/m/Y'), | |
'd4' => parseTimeString('2020/03/31', 'Y/m/d'), | |
'd5' => parseTimeString('2020/03', 'Y/m'), | |
'd6' => parseTimeString('03/2020', 'm/Y'), | |
]; | |
?> | |
<script> | |
<?php | |
foreach ($dates as $key => $value) { | |
echo "console.debug('{$key}', {$value}, new Date({$value}))" . PHP_EOL; | |
} | |
?> | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment