briannesbitt / Carbon

A simple PHP API extension for DateTime.
https://carbon.nesbot.com/
MIT License
16.59k stars 1.28k forks source link

isSameDay: Too few arguments #3021

Closed Timisorean closed 6 months ago

Timisorean commented 6 months ago

Hello,

I encountered an issue with the following code:

Carbon::parse('2018-06-01')->isSameDay()

Carbon version: v3.3.1

PHP version: v8.1.3

Error:

Too few arguments to function Carbon\Carbon::isSameUnit(), 1 passed in .../vendor/nesbot/carbon/src/Carbon/Traits/Date.php on line 2894 and exactly 2 expected

But it works when passing Carbon::now() as first argument. Cannot pass null or leave out like doc say:

Checks if the given date is in the same day as the instance. If null passed, compare to now (with the same timezone).

Worked in Carbon v2.

Thanks!

kylekatarnls commented 6 months ago

Hello, since Carbon 3, you need to choose between:

Checking if a date is today/current day so no argument is needed as it's unambigous:

Carbon::parse('2018-06-01')->isToday()
Carbon::parse('2018-06-01')->isCurrentDay()

Or comparing 2 dates and see if they both are on the same day, in this case it's required (for explicitly) to clearly state the 2 dates:

Carbon::parse('2018-06-01')->isSameDay('2024-05-19')

The argument can be a date string, DateTime, or Carbon object.

Thanks.