Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ethiopic date lib #2662

Open
wants to merge 12 commits into
base: ethiopic-calendar
Choose a base branch
from

Conversation

temesgen-mulugeta
Copy link

Add Ethiopic (Ethiopian) Calendar Support

This PR adds initial support for the Ethiopic calendar system to react-day-picker.

Implementation Details

  • Added core Ethiopic calendar utility functions in src/ethiopic/utils/ethiopicDateUtils.ts:
    • Date conversion between Gregorian and Ethiopic calendars
    • Ethiopic calendar calculations (leap years, month lengths)
    • Month and day name localization in Amharic
  • Created date manipulation functions in src/ethiopic/lib/:
    • addMonths, addYears
    • startOfMonth, endOfMonth
    • startOfYear, endOfYear
    • getMonth, getYear, getWeek
    • isSameMonth, isSameYear
    • Other utility functions
  • Added Ethiopic calendar component in src/ethiopic/index.tsx

Current Status

  • ⚠️ Tests are pending for the utility functions and components
  • ⚠️ UI testing is needed
  • ✅ Core date conversion and calculations are implemented
  • ✅ Basic component structure is in place

@gpbl
Copy link
Owner

gpbl commented Jan 12, 2025

Awesome work! Thanks so much for taking the time for this.

Let me fix the conflicts... I came up late with my scaffolding thing!

@gpbl gpbl self-requested a review January 12, 2025 17:50
@gpbl
Copy link
Owner

gpbl commented Jan 12, 2025

@temesgen-mulugeta@temesgen-mulugeta I’ll need to refactor some of the code here for merging. Please wait before making any more changes, thanks!

@gpbl gpbl changed the title Feature/ethiopic calendar update feat: ethiopic date lib Jan 12, 2025
Copy link
Owner

@gpbl gpbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated your pull request to reduce the code diff from the target branch and align it with the repository’s conventions.

I’ll provide more detailed comments on the code later. Here are some suggestions I found:

  • Replace the functions working with Gregorian dates with date-fans functions.
  • Some functions appear unused by the calendar (e.g., the difference between Ethiopic days). Should we remove them?
  • Move other functions, such as addDays, to the lib directory.
  • Organize the localization code into a locale, possibly following the Locale shape by date-fns.
  • I’m still unclear about input validation and error handling. I see some "defensive" code but it's not clear when such error condition could happen.

The most critical aspect missing now is the testing. It’s not essential that the tests pass, but they should clearly demonstrate how each function works.

Without tests, we can’t make changes or understand why the calendar isn’t working correctly. I recommend starting with the simplest functions and gradually moving to the most complex ones.

@gpbl
Copy link
Owner

gpbl commented Jan 14, 2025

I could compile a list of the months and its behavior that we should probably test (assuming the list is correct):

  • Meskerem (2016)
    Regular start of a year. Tests transition from Gregorian calendar.
    • Week in Month: 5
    • Days in Month: 30
    • Expected Outside Days: [September 4–10, October 1–2]
    • Gregorian Month Range: September 11–October 10
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 30]
  • Pagumē (2016, Leap)
    Ethiopian leap year with a 6-day 13th month.
    • Weeks in Month: 1
    • Days in Month: 6
    • Expected Outside Days: [September 6–10]
    • Gregorian Month Range: September 6–10
    • Is Leap Month: true
    • Days: [1, 2, 3, 4, 5, 6]
  • Pagumē (2017, Non-Leap)
    Regular 5-day Pagumē in a non-leap year.
    • Weeks in Month: 1
    • Days in Month: 5
    • Expected Outside Days: [September 6–10]
    • Gregorian Month Range: September 6–10
    • Is Leap Month: false
    • Days: [1, 2, 3, 4, 5]
  • Tahsas (2017)
    Crosses over Gregorian New Year (December to January). Tests boundary handling.
    • Weeks in Month: 4
    • Days in Month: 23
    • Expected Outside Days: [November 27–30, January 1–3]
    • Gregorian Month Range: December 8–December 31
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 23]
  • Meskerem (2008)
    This year starts exactly 8 years behind the Gregorian calendar.
    • Weeks in Month: 5
    • Days in Month: 30
    • Expected Outside Days: [September 4–10, October 1–2]
    • Gregorian Month Range: September 11–October 10
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 30]
  • Ginbot (2025)
    Tests synchronization with May and June in Gregorian calendar.
    • Weeks in Month: 5
    • Days in Month: 30
    • Expected Outside Days: [April 28–30, June 1–2]
    • Gregorian Month Range: May 9–June 7
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 30]
  • Yekatit (2100, Non-Leap)
    Ensures system skips Gregorian leap year in 2100 correctly.
    • Weeks in Month: 5
    • Days in Month: 30
    • Expected Outside Days: [January 29–31, March 1–2]
    • Gregorian Month Range: February 8–March 9
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 30]
  • Pagumē (2096, Leap)
    Tests handling of a leap year in a far-future scenario.
    • Weeks in Month: 1
    • Days in Month: 6
    • Expected Outside Days: [September 6–10]
    • Gregorian Month Range: September 6–10
    • Is Leap Month: true
    • Days: [1, 2, 3, 4, 5, 6]
  • Hidar (2023)
    Non-edge case: Regular month in a non-leap year to validate normal behavior.
    • Weeks in Month: 5
    • Days in Month: 30
    • Expected Outside Days: [October 29–31, December 1–2]
    • Gregorian Month Range: November 10–December 9
    • Is Leap Month: false
    • Days: [1, 2, 3, ..., 30]

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