@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement getNthBusinessDay()

Summary: I will need it for nagging tool.

Test Plan:
None yet.
Please suggest me how to create a testing database (I need to insert some data in the table). I guess that it is now possible?
There is also probably some bug in `arc unit` - `setEnvConfig()` is not called before `getEnvConfig()` resulting in fatal error.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2376

vrana 631718f9 45c662e4

+92
+2
src/__phutil_library_map__.php
··· 531 531 'PhabricatorCalendarController' => 'applications/calendar/controller/base', 532 532 'PhabricatorCalendarDAO' => 'applications/calendar/storage/base', 533 533 'PhabricatorCalendarHoliday' => 'applications/calendar/storage/holiday', 534 + 'PhabricatorCalendarHolidayTestCase' => 'applications/calendar/storage/holiday/__tests__', 534 535 'PhabricatorChangesetResponse' => 'infrastructure/diff/response', 535 536 'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/channellist', 536 537 'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/channellog', ··· 1465 1466 'PhabricatorCalendarController' => 'PhabricatorController', 1466 1467 'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO', 1467 1468 'PhabricatorCalendarHoliday' => 'PhabricatorCalendarDAO', 1469 + 'PhabricatorCalendarHolidayTestCase' => 'PhabricatorTestCase', 1468 1470 'PhabricatorChangesetResponse' => 'AphrontProxyResponse', 1469 1471 'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController', 1470 1472 'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController',
+18
src/applications/calendar/storage/holiday/PhabricatorCalendarHoliday.php
··· 27 27 ) + parent::getConfiguration(); 28 28 } 29 29 30 + public static function getNthBusinessDay($epoch, $n) { 31 + // Sadly, there are not many holidays. So we can load all of them. 32 + $holidays = id(new PhabricatorCalendarHoliday())->loadAll(); 33 + $holidays = mpull($holidays, null, 'getDay'); 34 + $interval = ($n > 0 ? 1 : -1) * 24 * 60 * 60; 35 + 36 + $return = $epoch; 37 + for ($i = abs($n); $i > 0; ) { 38 + $return += $interval; 39 + $weekday = date('w', $return); 40 + if ($weekday != 0 && $weekday != 6 && // Sunday and Saturday 41 + !isset($holidays[date('Y-m-d', $return)])) { 42 + $i--; 43 + } 44 + } 45 + return $return; 46 + } 47 + 30 48 }
+2
src/applications/calendar/storage/holiday/__init__.php
··· 8 8 9 9 phutil_require_module('phabricator', 'applications/calendar/storage/base'); 10 10 11 + phutil_require_module('phutil', 'utils'); 12 + 11 13 12 14 phutil_require_source('PhabricatorCalendarHoliday.php');
+55
src/applications/calendar/storage/holiday/__tests__/PhabricatorCalendarHolidayTestCase.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class PhabricatorCalendarHolidayTestCase extends PhabricatorTestCase { 20 + 21 + protected function getPhabricatorTestCaseConfiguration() { 22 + return array( 23 + self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 24 + ); 25 + } 26 + 27 + protected function willRunTests() { 28 + parent::willRunTests(); 29 + id(new PhabricatorCalendarHoliday()) 30 + ->setDay('2012-01-02') 31 + ->setName('International Testing Day') 32 + ->save(); 33 + } 34 + 35 + public function testNthBusinessDay() { 36 + $map = array( 37 + array('2011-12-30', 1, '2012-01-03'), 38 + array('2012-01-01', 1, '2012-01-03'), 39 + array('2012-01-01', 0, '2012-01-01'), 40 + array('2012-01-01', -1, '2011-12-30'), 41 + array('2012-01-04', -1, '2012-01-03'), 42 + ); 43 + foreach ($map as $val) { 44 + list($date, $n, $expect) = $val; 45 + $actual = PhabricatorCalendarHoliday::getNthBusinessDay( 46 + strtotime($date), 47 + $n); 48 + $this->assertEqual( 49 + $expect, 50 + date('Y-m-d', $actual), 51 + "{$n} business days since '{$date}'"); 52 + } 53 + } 54 + 55 + }
+15
src/applications/calendar/storage/holiday/__tests__/__init__.php
··· 1 + <?php 2 + /** 3 + * This file is automatically generated. Lint this module to rebuild it. 4 + * @generated 5 + */ 6 + 7 + 8 + 9 + phutil_require_module('phabricator', 'applications/calendar/storage/holiday'); 10 + phutil_require_module('phabricator', 'infrastructure/testing/testcase'); 11 + 12 + phutil_require_module('phutil', 'utils'); 13 + 14 + 15 + phutil_require_source('PhabricatorCalendarHolidayTestCase.php');