note 117847 added to function.date

From: Date: Wed, 19 Aug 2015 13:23:08 +0000
Subject: note 117847 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-203388@lists.php.net to get a copy of this message
<? /** * This function gives you the next working days based on the buffer * * @param $date must be in YYYY-MM-DD format * @param int $buffer * @param string $holidays - You can pass either an array of holidays in YYYYYMMDD format or a URL for a .ics file * containing holidays this defaults to the UK govt holiday data for England and Wales * @return string */ function getWorkingDays($date,$buffer=1,$holidays='') { if ($holidays==='') $holidays = 'https://www.gov.uk/bank-holidays/england-and-wales.ics'; if (!is_array($holidays)) { $ch = curl_init($holidays); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $ics = curl_exec($ch); curl_close($ch); $ics = explode("\n",$ics); $ics = preg_grep('/^DTSTART;/',$ics); $holidays = preg_replace('/^DTSTART;VALUE=DATE:(\\d{4})(\\d{2})(\\d{2}).*/s','$1-$2-$3',$ics); } $addDay = 0; while ($buffer--) { while (true) { $addDay++; $newDate = date('Y-m-d', strtotime("$date +$addDay Days")); $newDayOfWeek = date('w', strtotime($newDate)); if ( $newDayOfWeek>0 && $newDayOfWeek<6 && !in_array($newDate,$holidays)) break; } } return $newDate; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 213.106.224.69 ---- Manual Page -- http://php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/117847 Del: integrated -- https://master.php.net/note/delete/117847/integrated Del: useless -- https://master.php.net/note/delete/117847/useless Del: bad code -- https://master.php.net/note/delete/117847/bad+code Del: spam -- https://master.php.net/note/delete/117847/spam Del: non-english -- https://master.php.net/note/delete/117847/non-english Del: in docs -- https://master.php.net/note/delete/117847/in+docs Del: other reasons-- https://master.php.net/note/delete/117847 Reject -- https://master.php.net/note/reject/117847 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203388) next »