Skip to content

Instantly share code, notes, and snippets.

@bmcminn
Last active April 2, 2020 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcminn/9748b9df0a632a06d9fe780179ab2f57 to your computer and use it in GitHub Desktop.
Save bmcminn/9748b9df0a632a06d9fe780179ab2f57 to your computer and use it in GitHub Desktop.
Testing date parsing in regards to leap year 2020
<!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