DiffInMinutes突然出错

时间:2019-02-13 16:35:04

标签: php php-carbon

我使用carbon来管理PHP中的时间信息,它的工作原理非常好。我现在发现,当用户请求14:00至16:00的东西时,它会增加几个(或更多)小时的时间。

我调试了一下,发现一切都错了。

                $current = Carbon::parse($formattedDate . ' ' . $request->from);
                $until = Carbon::parse($formattedDate . ' ' . $request->until, '0');

                $records = array();
                while ($current->diffInMinutes($until, false) >= 0) {

                    $records[] = [
                        'day' => $formattedDate,
                        'hour' => $current->format('H:i:s')
                    ];
                    // This is the part that I use to debug
                    print $current . ' is ';
                    print $current->diffInMinutes($until);
                    print ' away from ' . $until . '<br /><br />';

                    $current->addMinutes($request->step);
                }
                die();
            }

所以$request->from10:00,而$request->until11:00$request->step30。这些都是转储的,我什至尝试在代码中设置它们。

我收到的最高代码是:

2019-02-23 10:00:00 is 240 away from 2019-02-23 11:00:00
2019-02-23 10:30:00 is 210 away from 2019-02-23 11:00:00
2019-02-23 11:00:00 is 180 away from 2019-02-23 11:00:00
2019-02-23 11:30:00 is 150 away from 2019-02-23 11:00:00
2019-02-23 12:00:00 is 120 away from 2019-02-23 11:00:00
2019-02-23 12:30:00 is 90 away from 2019-02-23 11:00:00
2019-02-23 13:00:00 is 60 away from 2019-02-23 11:00:00
2019-02-23 13:30:00 is 30 away from 2019-02-23 11:00:00
2019-02-23 14:00:00 is 0 away from 2019-02-23 11:00:00

如您所见,所有这些分钟差都是错误的(第一个应该是60分钟)。这段代码曾经可以正常工作-知道我在做什么不对吗?

0 个答案:

没有答案
相关问题