alisinabh
Jalaali (Shamsi) calendar for elixir (Persian calendar)
Hey everyone
i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice versa.
Jalaali is also known as Persian calendar or Shamsi calendar and is widely used in Persia and Afghanistan.
its available in hex with name of :jalaali
its pretty easy to use
iex> jalaali_dat = Jalaali.to_jalaali(DateTime.utc_now)
and…
iex> Jalaali.to_gregorian(jalaali_date)
hope you guys enjoy using it (if you ever need
) ,
Thanks
Most Liked
josevalim
Thank you for the package!
Btw, Elixir calendar types supports custom calendars. By default we use Calendar.ISO but there is a field on every struct called :calendar which you could store your custom calendar and it would be invoked when appropriate by Elixir.
I would love to know if you tried implementing the Jalaali on top of Elixir date types. I will be glad to answer any question you may have about the process or fix any bug you spot.
alisinabh
Hey Jose
First of all i wanted to thank you for creating elixir and maintaining it. You are really active and passionate about it.
I just began learning elixir in about 20 days and i am absolutely in love with it and its community, where every one is trying to do their best to keep it perfect.
Unfortunately i did not know that i can change :calendar in Date for localization. shame on me i’m a bit lazy with reading docs! 
But i will fix that and make it to work as a Calendar.
I will let you know about the process and if i got to anything i couldn’t solve i will ask for your help
Thank you for your support you just made me get more and more excited about Elixir. 
P.S: Did i forgot to say that “YOU ARE AWESOME”?
alisinabh
Jalaali 0.2.0 is Released!
Hi everyone.
The new version of Jalaali is released supporting Elixir Calendar system announced in Elixir 1.5
In the new system Dates/DateTimes can be converted easily thanks to @qqwy and @josevalim
You can easily type DateTime.utc_now(Jalaali.Calendar) in order to get current DateTime in any calendar (in this example Jalaali)
Or you can use Date.convert or DateTime.convert functions to convert any Date/DateTime to any calendar implemented in Elixir.
For more information on how to use this new features you can either read Jalaali docs github.com/jalaali/elixir-jalaali or Elixir calendar docs.
Please report any issues you encounter while using Jalaali.
Thanks
Qqwy
Let me clarify that I’m not at all an expert at time systems, but having a love of clocks, astronomy and weird human constructs here are my two cents:
- To make precise timestamp conversions between two different calendars, it is useful to find a simple and unambigous (i.e. no discontinuities like leap days, daylight savings time, leap seconds etc.) ‘standard’ intermediate representation.
- I might be wrong, but the TAI (International Atomic Time) seems to fit this description. This is the standard that is used in, amongst other places, space travel. It does not use leap days or leap seconds. It simply counts time (in SI-seconds) since the defined starting point. The timescale used by the GPS might be even easier to use (it it always exactly 19 seconds behind TAI, but otherwise is the same) as its starting point is equal to 1958-01-01 0:00 UTC.
Joda time indeed is a great reference; I really like their approach to Periods (a set of amounts, i.e. some days, some hours, some minutes, some seconds that are added in turn and thus keep in mind discontinuities like daylight savings time.) vs Durations (an exact amount of milliseconds.)
josevalim
@alisinabh since you are the first person doing the integration, if there is a bug, it is very likely on our side. 
The Calendar callbacks are only for existing Date, NaiveDateTime and DateTime. There are no functions in Date, NaiveDateTime and DateTime for creating custom dates in other calendars. So my advice would be for you to create a module Jallali with functions such as:
Jallali.date(year, month, date)
Jallali.utc_naive_datetime()
...
And so on and make those return a Date, NaiveDateTime, etc with the calendar field set to Jallali.Calendar.
Does this make things a bit clearer? 







