note 96385 deleted from function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:39:54 +0000
Subject: note 96385 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201185@lists.php.net to get a copy of this message
Note Submitter: karim at sweetcode dot co dot uk ---- 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', $utDate ), $holidays ) ) ; } ?>

« previous php.notes (#201185) next »