为什么 carbon 之间 returns 无效数据?

Why carbon between returns invalid data?

在 laravel 8 我需要检查 $adItem->expire_date 是否会在接下来的 3 天内结束($fullcalendar_nearest_days) 并制作

$today = Carbon::today()->startOfDay();
\Log::info(varDump($adItem->expire_date, ' -00 $adItem->expire_date::'));
\Log::info(varDump($today, ' -1 $today::'));

$expireDateCheckNearest = $today->addDays($fullcalendar_nearest_days)->startOfDay();
\Log::info(varDump($expireDateCheckNearest, ' -1 $expireDateCheckNearest::'));


//                                       2021-06-30            2021-06-29      2021-07-02
$is_fullcalendar_nearest_days = $adItem->expire_date->between($today,         $expireDateCheckNearest);
\Log::info(varDump($is_fullcalendar_nearest_days, ' -1 $is_fullcalendar_nearest_days::'));

我看到日志输出:

[2021-06-29 07:51:02] local.INFO:  (Object of Illuminate\Support\Carbon) : -00 $adItem->expire_date:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc40000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)

[ * dumpLocale] =>
[date] => 2021-06-30 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)

[2021-06-29 07:51:02] local.INFO:  (Object of Carbon\Carbon) : -1 $today:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc50000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)

[ * dumpLocale] =>
[date] => 2021-06-29 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)

[2021-06-29 07:51:02] local.INFO:  (Object of Carbon\Carbon) : -1 $expireDateCheckNearest:: : Array
(
[ * endOfTime] =>
[ * startOfTime] =>
[ * constructedObjectId] => 0000000029721fc50000000037698813
[ * localMonthsOverflow] =>
[ * localYearsOverflow] =>
[ * localStrictModeEnabled] =>
[ * localHumanDiffOptions] =>
[ * localToStringFormat] =>
[ * localSerializer] =>
[ * localMacros] =>
[ * localGenericMacros] =>
[ * localFormatFunction] =>
[ * localTranslator] =>
[ * dumpProperties] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)

[ * dumpLocale] =>
[date] => 2021-07-02 00:00:00.000000
[timezone_type] => 3
[timezone] => Europe/Kiev
)

[2021-06-29 07:51:02] local.INFO: scalar => (boolean) : -1 $is_fullcalendar_nearest_days:: :   

我假设2021-06-30在2021-06-29和2021-07-02之间,抓不到 为什么 $is_fullcalendar_nearest_days == false ?

使用addDays()添加天数:

Carbon::now()->addDays(3);

此外,将此添加到查询中以获取总是一个好主意

->where('expire_date', '>', Carbon::now()->addDays(3))