fork(2) download
  1. <?php
  2. function get_next_contest_date($current_date) {
  3. $current_date_obj = new DateTime($current_date);
  4.  
  5. $year = $current_date_obj->format("Y");
  6. $first_day_of_year = date('D', strtotime("$year-01-01"));
  7.  
  8. $week = $current_date_obj->format("W");
  9. $contest_week = $week;
  10.  
  11. if($first_day_of_year !== 'Mon') {
  12. $contest_week--;
  13. }
  14.  
  15. $end_date_obj = new DateTime();
  16.  
  17. if($contest_week & 1) {
  18. $end_date_obj->setISODate($year, $week + 2);
  19. } else {
  20. $end_date_obj->setISODate($year, $week + 1);
  21. }
  22.  
  23. return $end_date_obj->format('Y-m-d');
  24. }
  25.  
  26. echo get_next_contest_date('2014-01-11') . "\n";
  27. echo get_next_contest_date('2014-02-01') . "\n";
  28. echo get_next_contest_date('2014-03-30') . "\n";
  29. echo get_next_contest_date('2014-03-31') . "\n";
Success #stdin #stdout 0.03s 20568KB
stdin
Standard input is empty
stdout
2014-01-20
2014-02-03
2014-03-31
2014-04-14