Coder Social home page Coder Social logo

jalaali / elixir-jalaali Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 3.0 64 KB

Jalaali (also known as Jalali, Persian, Khorshidi, Shamsi) calendar implementation in Elixir.

Home Page: https://hex.pm/packages/jalaali

License: MIT License

Elixir 100.00%
jalaali calendar elixir shamsi datetime convert-dates khorshidi date

elixir-jalaali's Introduction

Elixir Jalaali calendar

Build Status Hex.pm GitHub license GitHub issues

Elixir implementation of jalaali.js which contains a Calendar implementation for jalaali and some functions for converting Jalaali and Gregorian calendar systems to each other.

Installation

You can install jalaali by Addding it to your list of dependencies in mix.exs:

def deps do
  [
    {:jalaali, "~> 0.4"}
  ]
end

Usage

After installing jalaali package. you can create Dates/DateTimes in jalaali or convert Dates/DateTimes form other calendars back an forth.

How to use

  • Creating new Date
  Date.new(1396, 6, 30, Jalaali.Calendar)
  {:ok, %Date{calendar: Jalaali.Calendar, day: 30, month: 6, year: 1396}}
  • Converting a DateTime to Jalaali
  datetime_in_any_calendar = DateTime.utc_now(Calendar.ISO)
  {:ok, jalaali_datetime} = DateTime.convert(datetime_in_any_calendar, Jalaali.Calendar)
  • Converting a DateTime from Jalaali
  jalaali_datetime = DateTime.utc_now(Jalaali.Calendar)
  {:ok, iso_datetime} = DateTime.convert(jalaali_datetime, Calendar.ISO)
  • Converting a Date to Jalaali
  date_in_any_calendar = Date.new(2017, 1, 1, Calendar.ISO)
  {:ok, jalaali_date} = Date.convert(date_in_any_calendar, Jalaali.Calendar)
  • Converting a Date from Jalaali
  {:ok, jalaali_date} = Date.new(1396, 6, 30, Jalaali.Calendar)
  {:ok, iso_date} = Date.convert(jalaali_date, Calendar.ISO)

Thats super easy. :)

License

This project is license under MIT.

For more information please check LICENSE

elixir-jalaali's People

Contributors

alisinabh avatar shahryarjb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

elixir-jalaali's Issues

`Mix.Config` is deprecated in elixir 1.13+

Hello, unfortunately, elixir config was changed in elixir 1.3 +, and we have warning about it. I checked this file to fix the issue, then I found this file Unnecessary. As we do not do any activities in this file, I mean we can deleteconfig.exs.

The Config module in Elixir was introduced in v1.9 as a replacement to Mix.Config, which was specific to Mix and has been deprecated.

And there is a guidance about config file

Important: if you are writing a library to be used by other developers, it is generally recommended to avoid the application environment, as the application environment is effectively a global storage. Also note that the config/config.exs of a library is not evaluated when the library is used as a dependency, as configuration is always meant to configure the current project. For more information, read our library guidelines.

ref: https://hexdocs.pm/elixir/master/Config.html#module-migrating-from-use-mix-config


I tested it with elixir 1.12 + and I have no error, but I think It works with versions higher than 1.9.

`dialyxir` should be updated for elixir 1.15

Dear @alisinabh,
We have a compile dependency error when we are in Elixir 1.15 and OTP 26, This error is because the dialyxir version has not been updated. I don't know if this will cause us to lose support for older versions.

I tested {:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false} version and it does not need to use --force

Thank you

`elixir-jalaali` is totally compatible with elixir 1.14

Test result

JalaaliTest [test/jalaali_test.exs]
  * doctest Jalaali.Calendar.quarter_of_year/3 (4) (0.00ms) [L#5]
  * doctest Jalaali.is_leap_jalaali_year/1 (3) (0.00ms) [L#4]
  * doctest Jalaali.Calendar.day_of_era/3 (1) (0.00ms) [L#5]
  * test Day number (2.8ms) [L#63]
  * doctest Jalaali.Calendar.year_of_era/1 (7) (0.00ms) [L#5]
  * test Day number in hundred days (0.01ms) [L#70]
  * doctest Jalaali.jalaali_month_length/2 (6) (0.00ms) [L#4]
  * doctest Jalaali.is_valid_jalaali_date?/1 (4) (0.00ms) [L#4]
  * test Fifth of Ordibehesht 1210 to gregorian (0.00ms) [L#42]
  * doctest Jalaali.to_jalaali/1 (15) (0.00ms) [L#4]
  * doctest Jalaali.to_gregorian/1 (11) (0.00ms) [L#4]
  * doctest Jalaali.Calendar.time_from_day_fraction/1 (5) (0.00ms) [L#5]
  * doctest Jalaali.Calendar.months_in_year/1 (3) (0.00ms) [L#5]
  * doctest Jalaali.to_jalaali/1 (14) (0.00ms) [L#4]
  * doctest Jalaali.to_gregorian/1 (12) (0.00ms) [L#4]
  * doctest Jalaali.to_gregorian/1 (10) (0.00ms) [L#4]
  * doctest Jalaali.Calendar.time_to_day_fraction/4 (6) (0.00ms) [L#5]
  * test 11th of Bahaman 1371 to gregorian and vice versa (0.00ms) [L#35]
  * doctest Jalaali.is_valid_jalaali_date?/1 (5) (0.00ms) [L#4]
  * doctest Jalaali.Calendar.day_of_year/3 (2) (0.00ms) [L#5]
  * doctest Jalaali.jalaali_month_length/2 (9) (0.00ms) [L#4]
  * doctest Jalaali.jalaali_month_length/2 (7) (0.00ms) [L#4]
  * test convert regular jalaali date to gregorian date (0.00ms) [L#7]
  * test Current time conversion back and forth (Jalaali first) (0.00ms) [L#55]
  * doctest Jalaali.is_leap_jalaali_year/1 (1) (0.00ms) [L#4]
  * test method works with old dates (0.00ms) [L#12]
  * test Day number in hundred days ago (0.01ms) [L#79]
  * test First of JAN 2000 to jalaali (0.00ms) [L#17]
  * doctest Jalaali.jalaali_month_length/2 (8) (0.00ms) [L#4]
  * test First of Farvardin 1350 to gregorian (0.00ms) [L#29]
  * doctest Jalaali.to_jalaali/1 (13) (0.00ms) [L#4]
  * test Day number on a specific date (0.00ms) [L#88]
  * test Current time conversion back and forth (Gregorian first) (0.01ms) [L#48]
  * doctest Jalaali.is_leap_jalaali_year/1 (2) (0.00ms) [L#4]
  * test Second of MAR 2150 to jalaali (0.00ms) [L#23]

Finished in 0.04 seconds (0.00s async, 0.04s sync)
22 doctests, 13 tests, 0 failures

Calendar behaviour error on elixir 1.8

Hello, I have some error that I think it was fixed before elixir 1.6 in blow link
#5

but in this version I mean elixir 1.8 these error were shown me again

Error

warning: function day_of_era/3 required by behaviour Calendar is not implemented (in module Jalaali.Calendar)
  lib/jalaali/calendar.ex:1

warning: function day_of_year/3 required by behaviour Calendar is not implemented (in module Jalaali.Calendar)
  lib/jalaali/calendar.ex:1

warning: function months_in_year/1 required by behaviour Calendar is not implemented (in module Jalaali.Calendar)
  lib/jalaali/calendar.ex:1

warning: function quarter_of_year/3 required by behaviour Calendar is not implemented (in module Jalaali.Calendar)
  lib/jalaali/calendar.ex:1

warning: function year_of_era/1 required by behaviour Calendar is not implemented (in module Jalaali.Calendar)
  lib/jalaali/calendar.ex:1

Thanks

Is there a plan to add some features to next version?

Hello maintainer,
I have a question which is β€œIs there a plan to add some features to next version?” or any way to improve this lib to keep it fresh?
I am going to create a new calendar UI with phoenix LiveView with your library help, but I am still interested on updating this project.
Thanks

spec for undefined function leap_year/1

Compile fails with elixir 1.6.1

== Compilation error in file lib/jalaali_calendar.ex ==
** (CompileError) lib/jalaali_calendar.ex:14: spec for undefined function leap_year/1
    (stdlib) lists.erl:1338: :lists.foreach/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.