I have implemented functions for converting dates between Persian and Gregorian calendars (algorithm by Kazimierz M. Borkowski). Is there a sample on how should I implement a full calendar?
Hello, you basically need to implement the Calendar
behaviour. There’s a similar project called jalaali
and the calendar implementation is here: https://github.com/jalaali/elixir-jalaali/blob/master/lib/jalaali/calendar.ex. There’s also a simple calendar used by Elixir tests here: https://github.com/elixir-lang/elixir/blob/master/lib/elixir/test/elixir/fixtures/calendar/holocene.exs.
And the Calendar documentation might also help you with properly implementing this.
And don’t be scared to look in the source code of the built-in Calendar.ISO calendar implementation, it is very readable !
Thanks!
There are parts that are not clear to me - at first glance - for example functions involve day and time frictions. And since months in Persian calendar are different from Gregorian months, there might be some corner cases for converting to/from string.
But I decided to not implement the full calendar for now because it is a big interface. I’ll come back to it later.
Just reinvented the wheel! Jalaali package is using the same algorithm! Should have mention it inside docs somewhere though.