taskTimeShift - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of taskTimeShift.php
- <?php
- define('REPORT_GEN_MIN', 3600); // 1 hour
- define('REPORT_GEN_MAX', 9000); // 2,5 hours
- define('ONE_DAY', 86400); // 1 day in secs
- function taskTimeShift($ts = 0, $minShift = REPORT_GEN_MIN, $maxShift = REPORT_GEN_MAX) {
- $ts = $ts ? $ts : time(); // Now
- $shift = rand($minShift, $maxShift); // Shift delta
- $tsGen = $ts + $shift; // shif timestamp
- $h = (int)date('H', $tsGen);
- //echo " $h | ";
- if ($h >= 19) { // after worktime
- $tsGen = strtotime(date('Y-m-d 08:30:00', $ts + ONE_DAY)) - $minShift; // On the next day at 8:30 o'clock
- $tsGen += $shift; // +1...3 hours (in sec)
- }
- elseif ($h < 9) { // before work time
- $tsGen = strtotime(date('Y-m-d 08:30:00', $ts)) - $minShift; // On this day as 8:30 o'clock
- if ($tsGen < $ts) $tsGen += ONE_DAY;
- $tsGen += $shift; // +1...3 hours (in sec)
- }
- return $tsGen;
- /*return [
- 'ts' => $tsGen,
- 'shift' => $shift
- ]; */
- }
- $ts = time()-10000;//+3600*3;
- for ( $i=0; $i < 1000; $i ++) {
- //echo date('H:i:s d.m.Y', taskTime($tsShift)). "\n";
- $tsShift = taskTimeShift($ts);
- echo date(' H:i d .m.Y', $ts);
- echo date(' --> H:i d .m.Y', $tsShift);
- printf(" ___ %.1f", ($tsShift - $ts)/3600.0);
- echo "\n";
- $ts+=60*5;
- }
File Description
- taskTimeShift
- PHP Code
- 24 Oct-2019
- 1.29 Kb
You can Share it:
Latest PHP Pastes