Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created December 25, 2017 14:31
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/a09003814e7fe7e8d6d36cd29397882b to your computer and use it in GitHub Desktop.
Save phpfiddle/a09003814e7fe7e8d6d36cd29397882b to your computer and use it in GitHub Desktop.
[ Posted by Eupseu@mail.ru ] https://otvet.mail.ru/question/205494522
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
</head>
<body class="row">
<?php
/*сейчас*/
$now = new DateTimeImmutable ();
$from_00 = DateTimeImmutable::createFromFormat('d.m.Y H:i:s', date('d.m.Y 00:00:00'));
$from_h = DateTimeImmutable::createFromFormat('d.m.Y H:i:s', date('d.m.Y H:00:00'));
$from_m = DateTimeImmutable::createFromFormat('d.m.Y H:i:s', date('d.m.Y H:i:00'));
if (isset($_REQUEST['from_h']))
$from_h = $from_h->setTime((int)$_REQUEST['from_h'], 0, 0);
if (isset($_REQUEST['from_m']))
$from_m = $from_m->setTime((int)$_REQUEST['from_h'], (int)$_REQUEST['from_m']);
$diff = $from_00->diff($now);
$diff_h = $from_h->diff($now);
$diff_m = $from_m->diff($now);
/*массив со строками*/
$rows = [
['name' => 'now', 'ord' => '0', 'value' => $now->format('d.m.Y:H:i:s'), 'label' => 'сейчас'],
['name' => 'from_00', 'ord' => '0', 'value' => $diff->format('%hч %iм %sс'), 'label' => 'прошло с начала суток', 'at' => $from_00->format('d.m.Y:H:i:s')],
['name' => 'from_h', 'ord' => '0', 'value' => $diff_h->format('%hч %iм %sс'), 'label' => 'прошло с начала часа', 'input' => true, 'at' => $from_h->format('d.m.Y:H:i:s')],
['name' => 'from_m', 'ord' => '0', 'value' => $diff_m->format('%hч %iм %sс'), 'label' => 'прошло с начала минуты', 'input' => true, 'at' => $from_m->format('d.m.Y:H:i:s')],
];
foreach ($rows as $row) {
$tr = [];
$tr[] = '<td>' . $row['label'] . '</td>';
if (isset($row['input'])) {
$tr[] = '<td><input type="number" name="' . $row['name'] . '" style="width: 45px;"/></td>';
}
$tr[] = '<td> <span>' . $row['at'] . '</span></td>';
$tr[] = '<td>' . $row['value'] . '</td>';
$table[] = '<tr>' . implode(PHP_EOL, $tr) . '</tr>';
}
$table[] = '<tr><td colspan="3"><input type="submit" value="отправить"></tr>';
echo '<form><table class="table">' . implode(PHP_EOL, $table) . '</form></table>';
//(c)alal
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment