Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created December 18, 2017 16:37
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 phpfiddle/b1a32d565bac9c99bd25a2b01597524d to your computer and use it in GitHub Desktop.
Save phpfiddle/b1a32d565bac9c99bd25a2b01597524d to your computer and use it in GitHub Desktop.
[ Posted by Eupseu@mail.ru ] https://otvet.mail.ru/question/205335977
<?php
/*для русских месяцев */
$overround = 'ini'.'_set';
$overround('date.timezone', 'Europe/Moscow');
if (isset($_REQUEST['send'])) {
try {
$date = DateTime::createFromFormat('d.m.Y', implode('.', [$_REQUEST['a'], $_REQUEST['b'], $_REQUEST['c']]));
if ($date == false)
throw new Exception('не верная дата');
$cal1 = IntlCalendar::fromDateTime($date->format('Y-m-d') . ' 00:00:00 Europe/Moscow');
/* на каком языке отображать*/
$result[] = IntlDateFormatter::formatObject($cal1, 'd MMMM yyyy HH:mm:ss VVVV', 'ru_RU');
$class = "green";
$errors = DateTime::getLastErrors();
if (!empty($errors['warning_count'])) {
$class = "warning";
$result [] = implode('<br>', $errors);
}
if ((int)$date->format('d') !== (int)$_REQUEST['a']) {
$class = "warning";
$result[] = '<em>кажется это не тот день который нужно</em>';
}
if ((int)$date->format('n') !== (int)$_REQUEST['b']) {
$class = "warning";
$result[] = '<em>кажется это не тот месяц который нужно</em>';
}
if ((int)$date->format('Y') !== (int)$_REQUEST['c']) {
$class = "warning";
$result[] = '<em>кажется это не тот год который нужно</em>';
}
} catch (\Exception $e) {
$result[] = $e->getMessage();
$class = "red";
}
}
$rows = '';
foreach (['a', 'b', 'c'] as $i)
$rows .=
'
<th><label for="' . $i . '">' . $i . '</label></th>
<td><input type="number" name="' . $i . '" id="' . $i . '"></td>
</tr>
<tr>';
$button = ' <tr>
<td></td>
<td><input type="submit" name="send" id="send" value="отправить"></td>
</tr>';
echo '<form><table>' . $rows . $button . '</table></form>' . (isset($result) ? PHP_EOL . "<div class ='$class' ><em>" . array_shift($result) . "</em>" . (empty($result) ? '' : '<ul>' . implode('<li>', $result) . '</ul>') . "</div>" : '');
?>
<style>.red {
background: rgba(255, 0, 0, 10);
}
.warning {
background: rgb(255, 165, 65);
}
.green {
background: rgb(18, 255, 56);
.red, .green, .warning {
border-radius: 10px;
padding: 10px;
}
}</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment