php - Add in an array records from today and tomorrow

My problem is logical, rather than strictly programming-related and I can't easily find a correct title to describe it in a single line...
I'm building a TV program app that will be pulling data from an ACF field in WordPress (irrelevant to my problem; I'm just mentioning it to better describe the situation).
So, the workflow when adding a new movie broadcast schedule is this:
When the movie is played on Monday at 14:00, they choose Monday from the date box, and type the correct time.
But when the movie is played after midnight (i.e. Tuesday 01:30), they choose Tuesday as the date...
Up to here everything makes sense... My problem is that when I need to display the movies of the day, I actually need to include the movies that will be broadcasted until the next day at 06:00.
So, for example, when I display the movies of Monday 7/12, I need to be displaying movies from Monday 7/12 06:00 up to Tuesday 8/12 05:59
(All hours mentioned above are 24-based)
How do I add this time offset?
The code I've written (that programmatically works 100% correct, except for that it doesn't take the time offset into consideration) is below (I've commented any part I felt might confuse you):
$posts = get_posts(array(
'post_type' => 'movie',
'numberposts' => -1, // This simply takes ALL records
'orderby' => array(
'ID' => 'ASC',
),
));
foreach ($posts as $post) {
$broadcasts = get_field('movie_broadcasts', $post->ID); // This is the command to get the ACF Repeater field data for each movie
if (is_array($broadcasts) && count($broadcasts)) {
foreach ($broadcasts as $broadcast) {
$timestamp = strtotime($broadcast['broadcast_date'][0] . ' ' . $broadcast['broadcast_time']); // Here I'm calculating the timestamp to limit below the movies that their broadcast happened in the past
if ($timestamp > time()) { // Here is where I limit past movies, AND I think here is the correct place to somehow add that time offset maybe?
$program[$broadcast['broadcast_date'][0]][] = array( // Here I "group" movies from the same day to a sub-array, and that where movies from tomorrow until 05:59 actually need to be added to
'movie' => $post->post_title,
'url' => get_permalink($post->post_id),
'channel' => $channels[$broadcast['broadcast_channel']],
'time' => $broadcast['broadcast_time'],
'poster' => get_field('movie_poster', $post->post_id),
);
}
}
}
}
array_multisort(array_map('strtotime', array_keys($program)), SORT_ASC, $program); // Here I'm sorting the days correctly
foreach ($program as &$day) {
array_multisort(array_column($day, 'time'), SORT_ASC, array_column($day, 'movie'), SORT_ASC, $day); // And here I'm further sorting the movies from each day according to their broadcast time - and according to their title in case they are scheduled to air at the same time (in a different channel of course)... Also, this sorting will cause further trouble when the movies from the next day will be included to the movies of today, as their broadcast time ie. 01:30 will be smaller than the broadcast time of a today's movie ie. 21:00
}
Generally the whole code needs re-consideration and re-work... Can someone help me with this? TIA
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.