Created
December 18, 2017 16:37
-
-
Save phpfiddle/b1a32d565bac9c99bd25a2b01597524d to your computer and use it in GitHub Desktop.
[ Posted by Eupseu@mail.ru ] https://otvet.mail.ru/question/205335977
This file contains 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
<?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