alisinabh

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 :smile:) ,
Thanks

Most Liked

josevalim

josevalim

Creator of Elixir

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

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! :disappointed_relieved:

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. :blue_heart:

P.S: Did i forgot to say that “YOU ARE AWESOME”?

alisinabh

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

Qqwy

TypeCheck Core Team

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

josevalim

Creator of Elixir

@alisinabh since you are the first person doing the integration, if there is a bug, it is very likely on our side. :slight_smile:

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? :slight_smile:

Where Next?

Popular in Libraries Top

mhanberg
I just released the first version of Temple: an HTML DSL for Elixir and Phoenix! You can read this blog post or the docs for more info...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
381 12391 119
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

Sub Categories:

We're in Beta

About us Mission Statement