PageRenderTime 54ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/epoch_3/bin/find-next-reset.php

https://github.com/Naddiseo/WW2Game
PHP | 53 lines | 36 code | 13 blank | 4 comment | 4 complexity | 9f4bd6849226a97c690de47ff95fbdf2 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?
  2. $cachedir = $argv[1];
  3. $current_age = $argv[2];
  4. require_once($cachedir . '/end_time.php');
  5. require_once($cachedir . '/start_time.php');
  6. // find the last friday of the (next) month
  7. $ori = new DateTime($_END_TIME[$current_age]);
  8. echo $ori->format('Y-m-d H:i:sP') . "\n";
  9. $year = $ori->format('Y');
  10. $m = $ori->format('m') + 1;
  11. $date = new DateTime(
  12. "$year-$m-01T12:59:59"
  13. );
  14. //echo "First of next month: " . $date->format('Y-m-d H:i:sP') . "\n";
  15. $startdate = $ori;
  16. $startdate->modify('+24hours 1second');
  17. echo "Start date: " . $startdate->format('c') . "\n";
  18. $lastday = 0;
  19. $month = $date->format('n');
  20. while ($month == $date->format('n')) {
  21. $date->modify('+1 day');
  22. $day = $date->format('N');
  23. #echo "day: $day\n";
  24. if ($day == 6) {
  25. $lastday = $date->format('U');
  26. //echo "current last day: " . $date->format('c') . "\n";
  27. }
  28. }
  29. echo "Last day = $lastday\n";
  30. $_START_TIME[$current_age + 1] = '@' . $startdate->format('U');
  31. $_END_TIME[$current_age + 1] = '@' . $lastday;
  32. echo "opening $cachedir/end_time.php\n";
  33. $endtime = fopen($cachedir . '/end_time.php', 'w+') or die("Couldn't' open end time\n");
  34. fwrite($endtime, '<? $_END_TIME = ' . var_export($_END_TIME, true) . ';?>');
  35. fclose($endtime);
  36. echo "opening $cachedir/start_time.php\n";
  37. $starttime = fopen($cachedir . '/start_time.php', 'w+') or die("Couldn't' open start time\n");
  38. fwrite($starttime, '<? $_START_TIME = ' . var_export($_START_TIME, true) . ';?>');
  39. fclose($starttime);
  40. ?>