.block-a {
color: red;
}
@media (max-width: 480px) {
.block-a {
color: blue;
}
}
.block-b {
color: blue;
}
@media (max-width: 480px) {
.block-b {
color: red;
}
}
.block-a {
color: red;
}
.block-b {
color: blue;
}
@media (max-width: 480px) {
.block-a {
color: blue;
}
.block-b {
color: red;
}
}
<?php
$empty = new DateTime('00:00:00');
$inside = clone $empty;
$outside = clone $empty;
$rows = [
['date' => '10.06.2015', 'time' => '10:12:42', 'enter-exit' => 1],
['date' => '10.06.2015', 'time' => '10:27:48', 'enter-exit' => 1], // отбрасываем
['date' => '10.06.2015', 'time' => '10:30:28', 'enter-exit' => 1], // отбрасываем
['date' => '10.06.2015', 'time' => '12:28:06', 'enter-exit' => 0],
['date' => '10.06.2015', 'time' => '12:30:17', 'enter-exit' => 1],
['date' => '10.06.2015', 'time' => '13:49:41', 'enter-exit' => 0],
['date' => '10.06.2015', 'time' => '14:04:56', 'enter-exit' => 1],
['date' => '10.06.2015', 'time' => '14:57:06', 'enter-exit' => 0],
['date' => '10.06.2015', 'time' => '15:11:13', 'enter-exit' => 1],
['date' => '10.06.2015', 'time' => '16:14:14', 'enter-exit' => 0],
['date' => '10.06.2015', 'time' => '19:10:21', 'enter-exit' => 0], // отбрасываем
['date' => '10.06.2015', 'time' => '19:21:38', 'enter-exit' => 0], // отбрасываем
];
foreach ($rows as $row) {
$datetime = $row['date'] . ' ' . $row['time'];
$datetime = DateTime::createFromFormat('d.m.Y H:i:s', $datetime);
if (!isset($need) || $need == $row['enter-exit']) {
if ($row['enter-exit']) {
$enter = $datetime;
if (isset($exit)) {
$interval = $enter->diff($exit);
$outside->add($interval);
}
} else {
$exit = $datetime;
if (isset($enter)) {
$interval = $exit->diff($enter);
$inside->add($interval);
}
}
$need = $row['enter-exit'] ? 0 : 1;
}
// Если нужно только выводить предупреждение, то раскомментируйте:
// else { echo 'Alert!'; break; }
}
echo 'В офисе: ' . $empty->diff($inside)->format('%h:%I:%S') . '<br>';
echo 'Вне офиса: ' . $empty->diff($outside)->format('%h:%I:%S');