从今天和明天添加一个数组记录

我的问题是合乎逻辑的,而不是严格与编程相关的,我无法轻易找到正确的标题来在一行中描述它...

我正在构建一个电视节目应用程序,它将从 WordPress 的 ACF 字段中提取数据(与我的问题无关;我只是为了更好地描述情况而提到它)。

因此,添加新电影播放时间表时的工作流程是这样的:

当电影在星期一 14:00 播放时,他们从日期框中选择星期一,并输入正确的时间。

但是当电影在午夜之后(即星期二 01:30)播放时,他们选择星期二作为日期...

从今天和明天添加一个数组记录

到这里一切都有意义...我的问题是,当我需要显示当天的电影时,我实际上需要包括将在第二天 06:00 播出的电影。

例如,当我显示 7/12 星期一的电影时,我需要显示从 7/12 星期一 06:00 到星期二 8/12 05:59 的电影

(以上所有时间均以 24 小时为准)

如何添加此时间偏移量?

我编写的代码(以编程方式工作 100% 正确,除了它不考虑时间偏移)如下(我已经评论了我认为可能会让您感到困惑的任何部分):

$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'),array_column($day,'movie'),$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 
}

通常整个代码需要重新考虑和重新工作......有人可以帮助我吗? TIA

iCMS 回答:从今天和明天添加一个数组记录

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/113138.html

大家都在问