public function testNthBusinessDay() { $map = array(array('2011-12-30', 1, '2012-01-03'), array('2012-01-01', 1, '2012-01-03'), array('2012-01-01', 0, '2012-01-01'), array('2012-01-01', -1, '2011-12-30'), array('2012-01-04', -1, '2012-01-03')); foreach ($map as $val) { list($date, $n, $expect) = $val; $actual = PhabricatorCalendarHoliday::getNthBusinessDay(strtotime($date), $n); $this->assertEqual($expect, date('Y-m-d', $actual), "{$n} business days since '{$date}'"); } }
#!/usr/bin/env php <?php /* * Copyright 2012 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $root = dirname(dirname(dirname(__FILE__))); require_once $root . '/scripts/__init_script__.php'; // http://www.opm.gov/operating_status_schedules/fedhol/ $holidays = array('2012-01-02' => "New Year's Day", '2012-01-16' => "Birthday of Martin Luther King, Jr.", '2012-02-20' => "Washington's Birthday", '2012-05-28' => "Memorial Day", '2012-07-04' => "Independence Day", '2012-09-03' => "Labor Day", '2012-10-08' => "Columbus Day", '2012-11-12' => "Veterans Day", '2012-11-22' => "Thanksgiving Day", '2012-12-25' => "Christmas Day", '2013-01-01' => "New Year's Day", '2013-01-21' => "Birthday of Martin Luther King, Jr.", '2013-02-18' => "Washington's Birthday", '2013-05-27' => "Memorial Day", '2013-07-04' => "Independence Day", '2013-09-02' => "Labor Day", '2013-10-14' => "Columbus Day", '2013-11-11' => "Veterans Day", '2013-11-28' => "Thanksgiving Day", '2013-12-25' => "Christmas Day", '2014-01-01' => "New Year's Day", '2014-01-20' => "Birthday of Martin Luther King, Jr.", '2014-02-17' => "Washington's Birthday", '2014-05-26' => "Memorial Day", '2014-07-04' => "Independence Day", '2014-09-01' => "Labor Day", '2014-10-13' => "Columbus Day", '2014-11-11' => "Veterans Day", '2014-11-27' => "Thanksgiving Day", '2014-12-25' => "Christmas Day", '2015-01-01' => "New Year's Day", '2015-01-19' => "Birthday of Martin Luther King, Jr.", '2015-02-16' => "Washington's Birthday", '2015-05-25' => "Memorial Day", '2015-07-03' => "Independence Day", '2015-09-07' => "Labor Day", '2015-10-12' => "Columbus Day", '2015-11-11' => "Veterans Day", '2015-11-26' => "Thanksgiving Day", '2015-12-25' => "Christmas Day"); $table = new PhabricatorCalendarHoliday(); $conn_w = $table->establishConnection('w'); $table_name = $table->getTableName(); foreach ($holidays as $day => $name) { queryfx($conn_w, 'INSERT IGNORE INTO %T (day, name) VALUES (%s, %s)', $table_name, $day, $name); }
public function render() { $user = $this->user; if (!$user) { throw new PhutilInvalidStateException('setUser'); } $fresh = PhabricatorEnv::getEnvConfig('differential.days-fresh'); if ($fresh) { $fresh = PhabricatorCalendarHoliday::getNthBusinessDay(time(), -$fresh); } $stale = PhabricatorEnv::getEnvConfig('differential.days-stale'); if ($stale) { $stale = PhabricatorCalendarHoliday::getNthBusinessDay(time(), -$stale); } $this->initBehavior('phabricator-tooltips', array()); $this->requireResource('aphront-tooltip-css'); $list = new PHUIObjectItemListView(); foreach ($this->revisions as $revision) { $item = id(new PHUIObjectItemView())->setUser($user); $icons = array(); $phid = $revision->getPHID(); $flag = $revision->getFlag($user); if ($flag) { $flag_class = PhabricatorFlagColor::getCSSClass($flag->getColor()); $icons['flag'] = phutil_tag('div', array('class' => 'phabricator-flag-icon ' . $flag_class), ''); } if ($revision->getDrafts($user)) { $icons['draft'] = true; } $modified = $revision->getDateModified(); $status = $revision->getStatus(); $show_age = ($fresh || $stale) && $this->highlightAge && !$revision->isClosed(); if ($stale && $modified < $stale) { $object_age = PHUIObjectItemView::AGE_OLD; } else { if ($fresh && $modified < $fresh) { $object_age = PHUIObjectItemView::AGE_STALE; } else { $object_age = PHUIObjectItemView::AGE_FRESH; } } $status_name = ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($status); if (isset($icons['flag'])) { $item->addHeadIcon($icons['flag']); } $item->setObjectName('D' . $revision->getID()); $item->setHeader($revision->getTitle()); $item->setHref('/D' . $revision->getID()); if (isset($icons['draft'])) { $draft = id(new PHUIIconView())->setIcon('fa-comment yellow')->addSigil('has-tooltip')->setMetadata(array('tip' => pht('Unsubmitted Comments'))); $item->addAttribute($draft); } /* Most things 'Need Review', so accept it's the default */ if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) { $item->addAttribute($status_name); } // Author $author_handle = $this->handles[$revision->getAuthorPHID()]; $item->addByline(pht('Author: %s', $author_handle->renderLink())); $reviewers = array(); // TODO: As above, this should be based on `getReviewerStatus()`. foreach ($revision->getReviewers() as $reviewer) { $reviewers[] = $this->handles[$reviewer]->renderLink(); } if (!$reviewers) { $reviewers = phutil_tag('em', array(), pht('None')); } else { $reviewers = phutil_implode_html(', ', $reviewers); } $item->addAttribute(pht('Reviewers: %s', $reviewers)); $item->setEpoch($revision->getDateModified(), $object_age); switch ($status) { case ArcanistDifferentialRevisionStatus::NEEDS_REVIEW: $item->setStatusIcon('fa-code grey', pht('Needs Review')); break; case ArcanistDifferentialRevisionStatus::NEEDS_REVISION: $item->setStatusIcon('fa-refresh red', pht('Needs Revision')); break; case ArcanistDifferentialRevisionStatus::CHANGES_PLANNED: $item->setStatusIcon('fa-headphones red', pht('Changes Planned')); break; case ArcanistDifferentialRevisionStatus::ACCEPTED: $item->setStatusIcon('fa-check green', pht('Accepted')); break; case ArcanistDifferentialRevisionStatus::CLOSED: $item->setDisabled(true); $item->setStatusIcon('fa-check-square-o black', pht('Closed')); break; case ArcanistDifferentialRevisionStatus::ABANDONED: $item->setDisabled(true); $item->setStatusIcon('fa-plane black', pht('Abandoned')); break; } $list->addItem($item); } $list->setNoDataString($this->noDataString); if ($this->header && !$this->noBox) { $list->setFlush(true); $list = id(new PHUIObjectBoxView())->setObjectList($list); if ($this->header instanceof PHUIHeaderView) { $list->setHeader($this->header); } else { $list->setHeaderText($this->header); } } else { $list->setHeader($this->header); } return $list; }