note 96385 added to function.strtotime

From: Date: Wed, 24 Feb 2010 12:17:52 +0000
Subject: note 96385 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-166315@lists.php.net to get a copy of this message
A handy function I wrote to tell you whether a given date (unix timestamp) is a working day in the UK. i.e. not a bank holiday or weekend day. Returns true or false. <?php function isUkWorkingDay( $utDate ) { /* weekend? */ if( date( 'N', $utDate ) > 5 ){ return false; } /* bank holiday? */ $year = date( 'Y', $utDate ); $utFirstJan = strtotime( '1st jan ' . $year ); $firstJanDay = date( 'N', $utFirstJan ); if ( $firstJanDay > 5 ){ // sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'first monday january ' . $year )); } else{ $holidays[] = date( 'Y-m-d', $utFirstJan) ; } $utEasterSunday = easter_date( $year ); $holidays[] = date( 'Y-m-d', strtotime( 'last friday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $utEasterSunday )); $holidays[] = date( 'Y-m-d', strtotime( 'first monday may ' . $year )); $holidays[] = date( 'Y-m-d', strtotime( 'last monday june ' . $year )); // end of may B.H. $holidays[] = date( 'Y-m-d', strtotime( 'last monday september ' . $year )); // end of August B.H. $xmasDay = date( strtotime( '25th december ' . $year ) ); if ( date( 'N', $xmasDay ) == 5 ){ // falls on friday $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); } if ( date( 'N', $xmasDay ) > 5 ){ // falls on sat or sun $holidays[] = date( 'Y-m-d', strtotime( 'next monday', $xmasDay )); $holidays[] = date( 'Y-m-d', strtotime( 'next tuesday', $xmasDay )); } if ( date( 'N', $xmasDay ) < 5 ){ // falls on mon to thurs $holidays[] = date( 'Y-m-d', $xmasDay ); $holidays[] = date( 'Y-m-d', strtotime( 'next day', $xmasDay )); } return( !in_array( date( 'Y-m-d' ), $holidays ) ) ; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 78.86.176.240 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/96385 Del: integrated -- https://master.php.net/note/delete/96385/integrated Del: useless -- https://master.php.net/note/delete/96385/useless Del: bad code -- https://master.php.net/note/delete/96385/bad+code Del: spam -- https://master.php.net/note/delete/96385/spam Del: non-english -- https://master.php.net/note/delete/96385/non-english Del: in docs -- https://master.php.net/note/delete/96385/in+docs Del: other reasons-- https://master.php.net/note/delete/96385 Reject -- https://master.php.net/note/reject/96385 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166315) next »