2019-09-07 14:37:00 +00:00
|
|
|
<?php
|
|
|
|
|
2019-09-08 22:41:52 +00:00
|
|
|
function ensure($bool, $error_msg = "")
|
|
|
|
{
|
2019-09-07 14:37:00 +00:00
|
|
|
if (!$bool)
|
|
|
|
throw new AssertionError($error_msg);
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:41:52 +00:00
|
|
|
function formatDate($date = NULL, $with_time = false)
|
|
|
|
{
|
2019-09-07 14:37:00 +00:00
|
|
|
if ($date == NULL)
|
2020-01-01 21:41:08 +00:00
|
|
|
$date = date("Y-m-d H:i:s");
|
2019-09-07 14:37:00 +00:00
|
|
|
|
|
|
|
return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date));
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:41:52 +00:00
|
|
|
function dateWellFormed($date, $with_time = false)
|
|
|
|
{
|
2020-01-01 21:41:08 +00:00
|
|
|
return date_parse_from_format($with_time ? "Y-m-d H:i:s" : "Y-m-d", $date) !== false;
|
2019-09-08 22:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function genRandomPhrase($size, $uppercase = false)
|
|
|
|
{
|
|
|
|
$alphabet = $uppercase ? "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" : "0123456789abcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
|
|
|
|
$phrase = "";
|
|
|
|
for ($i = 0; $i < $size; ++$i) {
|
|
|
|
$phrase .= $alphabet[rand(0, strlen($alphabet) - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $phrase;
|
2019-09-07 14:37:00 +00:00
|
|
|
}
|