[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/calendar/storage/ -> PhabricatorCalendarHoliday.php (source)

   1  <?php
   2  
   3  final class PhabricatorCalendarHoliday extends PhabricatorCalendarDAO {
   4  
   5    protected $day;
   6    protected $name;
   7  
   8    public function getConfiguration() {
   9      return array(
  10        self::CONFIG_TIMESTAMPS => false,
  11        self::CONFIG_COLUMN_SCHEMA => array(
  12          'day' => 'date',
  13          'name' => 'text64',
  14        ),
  15        self::CONFIG_KEY_SCHEMA => array(
  16          'day' => array(
  17            'columns' => array('day'),
  18            'unique' => true,
  19          ),
  20        ),
  21      ) + parent::getConfiguration();
  22    }
  23  
  24    public static function getNthBusinessDay($epoch, $n) {
  25      // Sadly, there are not many holidays. So we can load all of them.
  26      $holidays = id(new PhabricatorCalendarHoliday())->loadAll();
  27      $holidays = mpull($holidays, null, 'getDay');
  28      $interval = ($n > 0 ? 1 : -1) * 24 * 60 * 60;
  29  
  30      $return = $epoch;
  31      for ($i = abs($n); $i > 0; ) {
  32        $return += $interval;
  33        $weekday = date('w', $return);
  34        if ($weekday != 0 && $weekday != 6 && // Sunday and Saturday
  35            !isset($holidays[date('Y-m-d', $return)])) {
  36          $i--;
  37        }
  38      }
  39      return $return;
  40    }
  41  
  42  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1