trait Comparison

Trait Comparison.

Comparison utils and testers. All the following methods return booleans. nowWithSameTz

Depends on the following methods:

Properties

protectedbool $endOfTime
protectedbool $startOfTime

Methods

bool
eq(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is equal to another

bool
equalTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is equal to another

bool
ne(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is not equal to another

bool
notEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is not equal to another

bool
gt(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

bool
greaterThan(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

bool
isAfter(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

bool
gte(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than or equal to another

bool
greaterThanOrEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than or equal to another

bool
lt(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

bool
lessThan(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

bool
isBefore(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

bool
lte(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) or equal to another

bool
lessThanOrEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) or equal to another

bool
between(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2,bool$equal =true)

Determines if the instance is between two others.

bool
betweenIncluded(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Determines if the instance is between two others, bounds included.

bool
betweenExcluded(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Determines if the instance is between two others, bounds excluded.

bool
isBetween(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2,bool$equal =true)

Determines if the instance is between two others

bool
isWeekday()

Determines if the instance is a weekday.

bool
isWeekend()

Determines if the instance is a weekend day.

bool
isYesterday()

Determines if the instance is yesterday.

bool
isToday()

Determines if the instance is today.

bool
isTomorrow()

Determines if the instance is tomorrow.

bool
isFuture()

Determines if the instance is in the future, ie. greater (after) than now.

bool
isPast()

Determines if the instance is in the past, ie. less (before) than now.

bool
isLeapYear()

Determines if the instance is a leap year.

bool
isLongYear()

Determines if the instance is a long year

bool
isSameAs(string$format,Carbon|DateTimeInterface|string|null$date =null)

Compares the formatted values of the two dates.

bool
isSameUnit(string$unit,Carbon|DateTimeInterface|null$date =null)

Determines if the instance is in the current unit given.

bool
isCurrentUnit(string$unit)

Determines if the instance is in the current unit given.

bool
isSameQuarter(Carbon|DateTimeInterface|string|null$date =null,bool$ofSameYear =true)

Checks if the passed in date is in the same quarter as the instance quarter (and year if needed).

bool
isSameMonth(Carbon|DateTimeInterface|null$date =null,bool$ofSameYear =true)

Checks if the passed in date is in the same month as the instance´s month.

bool
isDayOfWeek(int$dayOfWeek)

Checks if this day is a specific day of the week.

bool
isBirthday(Carbon|DateTimeInterface|null$date =null)

Check if its the birthday. Compares the date/month values of the two dates.

bool
isLastOfMonth()

Check if today is the last day of the Month

bool
isStartOfDay(bool$checkMicroseconds =false)

Check if the instance is start of day / midnight.

bool
isEndOfDay(bool$checkMicroseconds =false)

Check if the instance is end of day.

bool
isMidnight()

Check if the instance is start of day / midnight.

bool
isMidday()

Check if the instance is midday.

static bool
hasFormat(string$date,string$format)

Checks if the (date)time string is in a given format.

static bool
hasFormatWithModifiers(string$date,string$format)

Checks if the (date)time string is in a given format.

static bool
canBeCreatedFromFormat(string$date,string$format)

Checks if the (date)time string is in a given format and valid to create a new instance.

bool
is(string$tester)

Returns true if the current date matches the given string.

bool
isStartOfTime()

Returns true if the date was created using CarbonImmutable::startOfTime()

bool
isEndOfTime()

Returns true if the date was created using CarbonImmutable::endOfTime()

static
resolveCarbon($date)

No description

static
copy()

No description

static
nowWithSameTz()

No description

Details

at line57
bool eq(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

equalTo()

at line76
bool equalTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line100
bool ne(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is not equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

notEqualTo()

at line119
bool notEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is not equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line140
bool gt(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

greaterThan()

at line159
bool greaterThan(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line183
bool isAfter(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

greaterThan()

at line204
bool gte(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than or equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

greaterThanOrEqualTo()

at line223
bool greaterThanOrEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is greater (after) than or equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line247
bool lt(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

lessThan()

at line266
bool lessThan(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line290
bool isBefore(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) than another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

lessThan()

at line311
bool lte(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) or equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

See also

lessThanOrEqualTo()

at line330
bool lessThanOrEqualTo(Carbon|DateTimeInterface|mixed$date)

Determines if the instance is less (before) or equal to another

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

bool

at line359
bool between(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2,bool$equal =true)

Determines if the instance is between two others.

The third argument allow you to specify if bounds are included or not (true by default) but for when you including/excluding bounds may produce different results in your application, we recommend to use the explicit methods ->betweenIncluded() or ->betweenExcluded() instead.

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2
bool $equal Indicates if an equal to comparison should be done

Return Value

bool

at line390
bool betweenIncluded(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Determines if the instance is between two others, bounds included.

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2

Return Value

bool

at line410
bool betweenExcluded(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Determines if the instance is between two others, bounds excluded.

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2

Return Value

bool

at line432
bool isBetween(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2,bool$equal =true)

Determines if the instance is between two others

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2
bool $equal Indicates if an equal to comparison should be done

Return Value

bool

at line448
bool isWeekday()

Determines if the instance is a weekday.

Return Value

bool

at line464
bool isWeekend()

Determines if the instance is a weekend day.

Return Value

bool

at line480
bool isYesterday()

Determines if the instance is yesterday.

Return Value

bool

at line496
bool isToday()

Determines if the instance is today.

Return Value

bool

at line512
bool isTomorrow()

Determines if the instance is tomorrow.

Return Value

bool

at line528
bool isFuture()

Determines if the instance is in the future, ie. greater (after) than now.

Return Value

bool

at line544
bool isPast()

Determines if the instance is in the past, ie. less (before) than now.

Return Value

bool

at line560
bool isLeapYear()

Determines if the instance is a leap year.

Return Value

bool

at line578
bool isLongYear()

Determines if the instance is a long year

at line597
bool isSameAs(string$format,Carbon|DateTimeInterface|string|null$date =null)

Compares the formatted values of the two dates.

Parameters

string $format date formats to compare.
Carbon|DateTimeInterface|string|null $date instance to compare with or null to use current day.

Return Value

bool

at line618
bool isSameUnit(string$unit,Carbon|DateTimeInterface|null$date =null)

Determines if the instance is in the current unit given.

Parameters

string $unit singular unit string
Carbon|DateTimeInterface|null $date instance to compare with or null to use current day.

Return Value

bool

Exceptions

BadComparisonUnitException

at line669
bool isCurrentUnit(string$unit)

Determines if the instance is in the current unit given.

Parameters

string $unit The unit to test.

Return Value

bool

Exceptions

BadMethodCallException

at line690
bool isSameQuarter(Carbon|DateTimeInterface|string|null$date =null,bool$ofSameYear =true)

Checks if the passed in date is in the same quarter as the instance quarter (and year if needed).

Parameters

Carbon|DateTimeInterface|string|null $date The instance to compare with or null to use current day.
bool $ofSameYear Check if it is the same month in the same year.

Return Value

bool

at line713
bool isSameMonth(Carbon|DateTimeInterface|null$date =null,bool$ofSameYear =true)

Checks if the passed in date is in the same month as the instance´s month.

Parameters

Carbon|DateTimeInterface|null $date The instance to compare with or null to use the current date.
bool $ofSameYear Check if it is the same month in the same year.

Return Value

bool

at line733
bool isDayOfWeek(int$dayOfWeek)

Checks if this day is a specific day of the week.

Parameters

int $dayOfWeek

Return Value

bool

at line757
bool isBirthday(Carbon|DateTimeInterface|null$date =null)

Check if its the birthday. Compares the date/month values of the two dates.

Parameters

Carbon|DateTimeInterface|null $date The instance to compare with or null to use current day.

Return Value

bool

at line776
bool isLastOfMonth()

Check if today is the last day of the Month

Return Value

bool

at line797
bool isStartOfDay(bool$checkMicroseconds =false)

Check if the instance is start of day / midnight.

Parameters

bool $checkMicroseconds check time at microseconds precision

Return Value

bool

at line823
bool isEndOfDay(bool$checkMicroseconds =false)

Check if the instance is end of day.

Parameters

bool $checkMicroseconds check time at microseconds precision

Return Value

bool

at line843
bool isMidnight()

Check if the instance is start of day / midnight.

Return Value

bool

at line861
bool isMidday()

Check if the instance is midday.

Return Value

bool

at line881
staticbool hasFormat(string$date,string$format)

Checks if the (date)time string is in a given format.

Parameters

string $date
string $format

Return Value

bool

at line904
staticbool hasFormatWithModifiers(string$date,string$format)

Checks if the (date)time string is in a given format.

Parameters

string $date
string $format

Return Value

bool

at line924
staticbool canBeCreatedFromFormat(string$date,string$format)

Checks if the (date)time string is in a given format and valid to create a new instance.

Parameters

string $date
string $format

Return Value

bool

at line963
bool is(string$tester)

Returns true if the current date matches the given string.

Parameters

string $tester day name, month name, hour, date, etc. as string

Return Value

bool

at line1071
bool isStartOfTime()

Returns true if the date was created using CarbonImmutable::startOfTime()

Return Value

bool

at line1081
bool isEndOfTime()

Returns true if the date was created using CarbonImmutable::endOfTime()

Return Value

bool

at line33
static resolveCarbon($date)

Parameters

$date

Return Value

static

at line33
static copy()

Return Value

static

at line33
static nowWithSameTz()

Return Value

static