Jump to content

calendar stops displaying daily work shifts after midnight


reverse_halo

Recommended Posts

I'm doing something wrong here and hoping someone can fil me in.  I have a routine that works great showing daily shifts up until midnight.  Meaning it will show shifts for Monday for example until it switches to Tuesday and then it shows Tuesday shifts.  This makes sense when the "day" is defined as 24 hours for each day.  I need the shifts to continue to show for Monday for example until 5 a.m. the following day.  So for example Monday shifts would continue to show until Tuesday 5 a.m.  After Tuesday 5 a.m., it would switch from showing Monday shifts to showing Tuesday shifts.  The same would be true of Wednesday 5 a.m., so on and so forth.   I created a variable entitled $day_end_each setting it to 5 a.m. and then adding it to the day range but it's not working.  Somehow it's completely ignored.  Any ideas?


$day_end_each = mktime(05,0,0,date("m"),date("d")+1,date("Y"));

$day_end_each = date("Y-m-d H:i:s", $day_end_each);

 

if ( date("Y-m-d", strtotime($row["shift_" . $i . "_start"])) == date("Y-m-d", strtotime($date_each)) && date("Y-m-d H:i:s", strtotime($row["shift_" . $i . "_start"])) <= $day_end_each && $row["member_shift_" . $i . "_on_call"] == 0 ) {
                

Link to comment
Share on other sites

You've got three conditionals happening in your if statement - do you know that $day_end_each is the part that's failing? Print out each of your conditionals and make sure you're focusing on the right one. Having no idea what $row['shift_{$x}_(start|end|on_call)'] actually contains, there are several ways the comparisons may have gone wrong.

Link to comment
Share on other sites

I would start off by using var_export to dump the result of each of your conditionals.

echo "<pre>".var_export(date("Y-m-d", strtotime($row["shift_" . $i . "_start"])) == date("Y-m-d", strtotime($date_each)), true)."</pre>";
echo "<pre>".var_export(date("Y-m-d H:i:s", strtotime($row["shift_" . $i . "_start"])) <= $day_end_each, true)."</pre>";
echo "<pre>".var_export($row["member_shift_" . $i . "_on_call"] == 0, true)."</pre>";

From there you can check if and where your logic chain is failing, and that'll give you a more specific place to start actually debugging.

Link to comment
Share on other sites

I'm working on the var_export now.  I greatly appreciate your help.  On a side note, the script runs using the server date and time.  Is there a way to tell the script it is Tuesday at 10 a.m. for example for testing purposes?  I was hoping there is a way to over-ride the shared hosting date/time in some manner or at least in way where the script believes it is a specified date/time.

Link to comment
Share on other sites

Where you assign $day_end_each, you've got several (frankly, redundant) calls to date() to define the month, day, and year. Replace those calls with specified values and you can set any date you'd like.

However, I have a sneaking suspicion that the problem may lie with the direction of your comparison. It seems like your query is working when considered from the start of the shift, but there's no consideration for the end of the shift. So perhaps there needs to be a condition that looks at $row['shift_'.$i.'_end'] or $row['shift_'.$i.'_start'] + $shift_duration (or something similar)?

Link to comment
Share on other sites

All that having been said, understand that any time span type calculation is ... just harder than it should be. You look at it and it's like "oh, yeah - no problem". Then you start actually working on it and it's far more complicated than you might think. So even the idea of comparing not only start time and end time as implied above, you suddenly then have to consider potentially time zones and then daylight savings time (which is it's own barrel of fish)...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.