I have a somewhat complicated time equation that had been driving me mental!
What I have so far is:
$current = time(); // UTC time
$user_in = '8:00 am'; // local time
$user_out = '4:00 pm'; // local time
$gmt_off = '11'; // Australia EST (+1 at the moment)
I then have the function that will convert the local time to UTC by subtracting the GMT offset, and output it as g:i a
function utc( $time ) {
$time = ( empty($time) ? null : strtotime($time) );
$gmt = '60 * 60 * 11'; // there is an actual check for it to be 10 or 11 - and in seconds
$out = ( $time - $gmt );
$out = date( 'Y-m-d g:i a', $out );
return $out;
}
What I cannot figure out is how to properly configure the conditions to check if the current time is outside the $user
times
$user_in_utc = utc( $user_in );
$user_out_utc = utc( $user_out );
if( $current < $user_in_utc && $current > $user_out_utc ) {
// do something
}
However, the problem I'm running into is that say current time is 6:00pm local time.
How do I check it is now currently less than $user_out
when it keeps saying the date is today and not tomorrow?
I intend for these functions to run if the statement being true as a cron task