Skip to content

Add isBirthday and isSameAsmethod to Jalalian class#199

Closed
alissn wants to merge 2 commits intomorilog:masterfrom
alissn:AddMethodIsBirthday
Closed

Add isBirthday and isSameAsmethod to Jalalian class#199
alissn wants to merge 2 commits intomorilog:masterfrom
alissn:AddMethodIsBirthday

Conversation

@alissn
Copy link
Copy Markdown

@alissn alissn commented Oct 18, 2025

Summary

Adds isBirthday method to Jalalian class based on Carbon's implementation. Compares month and day values while ignoring year, perfect for birthday comparisons in Jalali calendar.

Changes

  • New isSameAs() method: Compares formatted date values with flexible format support
  • New isBirthday() method: Checks if dates share same month/day (birthday comparison)
  • Comprehensive tests: 13 new test cases covering all scenarios

Usage

$birthday = new Jalalian(1376, 6, 5);
$birthday->isBirthday('1398-06-05'); // true
$birthday->isBirthday('1398-06-06'); // false
$birthday->isBirthday(); // compares with current date

@morilog
Copy link
Copy Markdown
Owner

morilog commented Oct 20, 2025

its not necessary methods for this package, so i reject the PR

@morilog morilog closed this Oct 20, 2025
@alissn
Copy link
Copy Markdown
Author

alissn commented Oct 20, 2025

Hi, @morilog

The reason for this PR is that, AYK in Gregorian leap years, birthdays can shift by one day when converting between calendars.

For example, if my birthday is stored in the database as 1996-01-15 (which equals 1374-10-25 in the Persian calendar):

  • My birthday in 2026 is 2026-01-15,
  • But in 2027 (a leap year), it becomes 2027-01-16.

In Laravel applications, date fields are often cast as 'date', so they return a Carbon instance when retrieved.
However, Carbon::isBirthday() compares only the 'md' (month and day) parts.
Because of the leap year shift, it incorrectly returns false.

This method helps handle such cases correctly .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants