function get_common_free_time($events, $duration, $date_first, $date_end, $time_first, $time_end) { $result = array(); $merged_events = merge_interleaved($events); $format = "Y-m-d H:i:s"; $initial_DT = DateTime::createFromFormat($format, $date_first . ' ' . $time_first); $end_DT = DateTime::createFromFormat($format, $date_first . ' ' . $time_end); $final_DT = DateTime::createFromFormat("Y-m-d", $date_end); $next_event = array_shift($merged_events); $next_event_DT = new DateTime(); if ($next_event != NULL) { $next_event_DT->setTimestamp($next_event["start_time"]); } $left_DT = clone $initial_DT; $right_DT = clone $end_DT; // stop when we reach the end of date filter while ($end_DT < $final_DT) { if ($next_event != NULL) { if ($next_event_DT >= $left_DT && $next_event_DT <= $right_DT) { if (duration_fits($left_DT, $next_event_DT, $duration)) { // we found a fit, add time to result array add_time($left_DT, $next_event_DT, $duration, $result); } // move $start to next point $left_DT->setTimeStamp($next_event["start_time"]); $interval = new DateInterval("PT{$next_event['duration']}M"); $left_DT->add($interval); $next_event = array_shift($merged_events); if ($next_event != NULL) { $next_event_DT->setTimestamp($next_event["start_time"]); } } else { if (duration_fits($left_DT, $right_DT, $duration)) { add_time($left_DT, $end_DT, $duration, $result); // we need to move $initial and $end to next period move_to_next_day($initial_DT, $end_DT); $left_DT = clone $initial_DT; $right_DT = clone $end_DT; } } } else { if (duration_fits($left_DT, $right_DT, $duration)) { add_time($left_DT, $end_DT, $duration, $result); } // we need to move $initial and $end to next period move_to_next_day($initial_DT, $end_DT); $left_DT = clone $initial_DT; $right_DT = clone $end_DT; } } return $result; }
$alert_class = "warning"; } else { if ($your == $_SESSION['num']) { $message = "哇!你真厲害!居然猜到這個數字是" . $_SESSION['num'] . "!<br />我又為你重新設定一個更難的數字,再去猜猜吧!"; $alert_class = "success"; rand_num(); } else { if ($your > $_SESSION['num']) { $message = "不對哦!不過我可以告訴你,答案比" . $your . "<strong>更小</strong>"; $alert_class = "warning"; add_time(1); } else { if ($your < $_SESSION['num']) { $message = "不對哦!不過我可以告訴你,答案比" . $your . "<strong>更大</strong>"; $alert_class = "warning"; add_time(1); } } } } ?> <div class="centerd <?php echo get_alert_class($alert_class); ?> "> <?php echo $message; ?> </div> <?php if ($_SESSION['time'] >= 30) {
/** * Registers a package in the process queue. * * @param Package $package * @param int $runtime * @param null $category */ public function registerPackage(Package $package, $runtime = 0, $category = null) { $process = ProcessQueue::create(['package' => get_class($package), 'data' => serialize($package), 'category' => $category, 'exec_datetime' => is_string($runtime) ? $runtime : add_time("{$runtime} minutes")]); //if there are errors let us know $this->throwErrors($process); }
function add_extra_chore($username, $chore, $time) { global $mysqli; $sql = $mysqli->prepare("INSERT INTO time_log(date,username,extra,extra_time) VALUES (CURDATE(),?,?,?)"); $sql->bind_param('ssi', $username, $chore, $time); if (!$sql->execute()) { print __FILE__ . ':' . __LINE__ . " (" . time() . ")<br/>\n"; die($mysqli->error); } $timeleft = add_time($username, $time); return array('done' => TRUE, 'timeleft' => $timeleft, 'username' => $username); }
#!/usr/bin/env php <?php require_once __DIR__ . '/app/lib.inc'; // Cron this once a minute. It will subtract one minute from whoever is Active on the computer $active = getActive(); foreach ($active as $username => $sessions) { $time_left = add_time($username, -1); if ($time_left < 0) { foreach ($sessions as $session) { $cmd = "/usr/local/bin/lock_screen.sh {$session['USER']} {$session['Display']}"; shell_exec($cmd); } } }