Skip to content

Commit

Permalink
Merge pull request #20 from shahryarjb/main
Browse files Browse the repository at this point in the history
Improve document
  • Loading branch information
alisinabh authored Aug 17, 2022
2 parents 8174508 + cfdd18f commit e2de9ed
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 94 deletions.
70 changes: 40 additions & 30 deletions lib/jalaali.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ defmodule Jalaali do
- ex_dt: Date or DateTime to convert
## Exmaples
iex> Jalaali.to_jalaali {2016, 12, 17}
{1395, 9, 27}
```elixir
iex> Jalaali.to_jalaali {2016, 12, 17}
{1395, 9, 27}
iex> Jalaali.to_jalaali {{2016, 12, 17}, {11, 11, 11}}
{{1395, 9, 27}, {11, 11, 11}}
iex> Jalaali.to_jalaali {{2016, 12, 17}, {11, 11, 11}}
{{1395, 9, 27}, {11, 11, 11}}
iex> Jalaali.to_jalaali ~D[2016-12-17]
~D[1395-09-27]
iex> Jalaali.to_jalaali ~D[2016-12-17]
~D[1395-09-27]
```
"""
@spec to_jalaali(tuple() | DateTime.t() | Date.t()) :: tuple() | DateTime.t() | Date.t()
def to_jalaali({gy, gm, gd}) do
Expand All @@ -71,14 +73,16 @@ defmodule Jalaali do
- ex_dt: Date or DateTime to convert
## Exmaples
iex> Jalaali.to_gregorian {1395, 9, 27}
{2016, 12, 17}
```elixir
iex> Jalaali.to_gregorian {1395, 9, 27}
{2016, 12, 17}
iex> Jalaali.to_jalaali {{2016, 12, 17}, {11, 11, 11}}
{{1395, 9, 27}, {11, 11, 11}}
iex> Jalaali.to_jalaali {{2016, 12, 17}, {11, 11, 11}}
{{1395, 9, 27}, {11, 11, 11}}
iex> Jalaali.to_gregorian ~D[1395-09-27]
~D[2016-12-17]
iex> Jalaali.to_gregorian ~D[1395-09-27]
~D[2016-12-17]
```
"""
@spec to_gregorian(tuple() | DateTime.t() | Date.t()) :: tuple() | DateTime.t() | Date.t()
def to_gregorian({jy, jm, jd}) do
Expand All @@ -101,11 +105,13 @@ defmodule Jalaali do
- arg1: is a tuple in shape of {jalaali_year, jalaali_month, jalaali_day}
## Examples
iex> Jalaali.is_valid_jalaali_date {1395, 9, 27}
true
```elixir
iex> Jalaali.is_valid_jalaali_date {1395, 9, 27}
true
iex> Jalaali.is_valid_jalaali_date {1395, 91, 27}
false
iex> Jalaali.is_valid_jalaali_date {1395, 91, 27}
false
```
"""
@spec is_valid_jalaali_date(tuple()) :: boolean()
def is_valid_jalaali_date?({jy, jm, jd}) do
Expand Down Expand Up @@ -133,14 +139,16 @@ defmodule Jalaali do
- jy: Jalaali Year (-61 to 3177)
## Examples
iex> Jalaali.is_leap_jalaali_year(1395)
true
```elixir
iex> Jalaali.is_leap_jalaali_year(1395)
true
iex> Jalaali.is_leap_jalaali_year(1396)
false
iex> Jalaali.is_leap_jalaali_year(1396)
false
iex> Jalaali.is_leap_jalaali_year(1394)
false
iex> Jalaali.is_leap_jalaali_year(1394)
false
```
"""
@spec is_leap_jalaali_year(integer()) :: boolean()
def is_leap_jalaali_year(jy) do
Expand All @@ -151,17 +159,19 @@ defmodule Jalaali do
Number of days in a given month in a Jalaali year.
## Examples
iex> Jalaali.jalaali_month_length(1395, 11)
30
```elixir
iex> Jalaali.jalaali_month_length(1395, 11)
30
iex> Jalaali.jalaali_month_length(1395, 6)
31
iex> Jalaali.jalaali_month_length(1395, 6)
31
iex> Jalaali.jalaali_month_length(1394, 12)
29
iex> Jalaali.jalaali_month_length(1394, 12)
29
iex> Jalaali.jalaali_month_length(1395, 12)
30
iex> Jalaali.jalaali_month_length(1395, 12)
30
```
"""
@spec jalaali_month_length(integer(), integer()) :: integer()
def jalaali_month_length(jy, jm) do
Expand Down
103 changes: 57 additions & 46 deletions lib/jalaali/calendar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ defmodule Jalaali.Calendar do
Returns the normalized day fraction of the specified time.
## Examples
iex> Calendar.ISO.time_to_day_fraction(0, 0, 0, {0, 6})
{0, 86400000000}
iex> Calendar.ISO.time_to_day_fraction(12, 34, 56, {123, 6})
{45296000123, 86400000000}
```elixir
iex> Calendar.ISO.time_to_day_fraction(0, 0, 0, {0, 6})
{0, 86400000000}
iex> Calendar.ISO.time_to_day_fraction(12, 34, 56, {123, 6})
{45296000123, 86400000000}
```
"""

Expand All @@ -194,10 +196,12 @@ defmodule Jalaali.Calendar do
Converts a day fraction to this Calendar's representation of time.
## Examples
iex> Calendar.ISO.time_from_day_fraction({1,2})
{12, 0, 0, {0, 6}}
iex> Calendar.ISO.time_from_day_fraction({13,24})
{13, 0, 0, {0, 6}}
```elixir
iex> Calendar.ISO.time_from_day_fraction({1,2})
{12, 0, 0, {0, 6}}
iex> Calendar.ISO.time_from_day_fraction({13,24})
{13, 0, 0, {0, 6}}
```
"""
@spec time_from_day_fraction(day_fraction()) :: {hour(), minute(), second(), microsecond()}
Expand Down Expand Up @@ -236,15 +240,16 @@ defmodule Jalaali.Calendar do
era for those years less than 1 defined as era `0`.
## Examples
iex> Jalaali.Calendar.year_of_era(1)
{1, 1}
iex> Jalaali.Calendar.year_of_era(1398)
{1398, 1}
iex> Jalaali.Calendar.year_of_era(0)
{1, 0}
iex> Jalaali.Calendar.year_of_era(-1)
{2, 0}
```elixir
iex> Jalaali.Calendar.year_of_era(1)
{1, 1}
iex> Jalaali.Calendar.year_of_era(1398)
{1398, 1}
iex> Jalaali.Calendar.year_of_era(0)
{1, 0}
iex> Jalaali.Calendar.year_of_era(-1)
{2, 0}
```
"""
@spec year_of_era(year) :: {year(), era :: 0..1}
def year_of_era(year) when is_integer(year) and year > 0, do: {year, 1}
Expand All @@ -257,26 +262,29 @@ defmodule Jalaali.Calendar do
It's always 12 for Jalaali calendar system.
## Examples
iex> Jalaali.Calendar.months_in_year(1398)
12
```elixir
iex> Jalaali.Calendar.months_in_year(1398)
12
```
"""
@spec months_in_year(year) :: 12
def months_in_year(_year), do: @months_in_year

@doc """
Calculates the quarter of the year from the given `year`, `month`, and `day`.
It is an integer from 1 to 4.
## Examples
iex> Jalaali.Calendar.quarter_of_year(1398, 1, 31)
1
iex> Jalaali.Calendar.quarter_of_year(123, 4, 3)
2
iex> Jalaali.Calendar.quarter_of_year(-61, 9, 31)
3
iex> Jalaali.Calendar.quarter_of_year(2678, 12, 28)
4
```elixir
iex> Jalaali.Calendar.quarter_of_year(1398, 1, 31)
1
iex> Jalaali.Calendar.quarter_of_year(123, 4, 3)
2
iex> Jalaali.Calendar.quarter_of_year(-61, 9, 31)
3
iex> Jalaali.Calendar.quarter_of_year(2678, 12, 28)
4
```
"""
@spec quarter_of_year(year, month, day) :: 1..4
def quarter_of_year(year, month, day)
Expand All @@ -287,16 +295,18 @@ defmodule Jalaali.Calendar do
@doc """
Calculates the day and era from the given `year`, `month`, and `day`.
## Examples
iex> Jalaali.Calendar.day_of_era(0, 1, 1)
{366, 0}
iex> Jalaali.Calendar.day_of_era(1, 1, 1)
{1, 1}
iex> Jalaali.Calendar.day_of_era(0, 12, 30)
{1, 0}
iex> Jalaali.Calendar.day_of_era(0, 12, 29)
{2, 0}
iex> Jalaali.Calendar.day_of_era(-1, 12, 29)
{367, 0}
```elixir
iex> Jalaali.Calendar.day_of_era(0, 1, 1)
{366, 0}
iex> Jalaali.Calendar.day_of_era(1, 1, 1)
{1, 1}
iex> Jalaali.Calendar.day_of_era(0, 12, 30)
{1, 0}
iex> Jalaali.Calendar.day_of_era(0, 12, 29)
{2, 0}
iex> Jalaali.Calendar.day_of_era(-1, 12, 29)
{367, 0}
```
"""
@spec day_of_era(year, month, day) :: {day :: pos_integer(), era :: 0..1}
def day_of_era(year, month, day)
Expand All @@ -316,13 +326,14 @@ defmodule Jalaali.Calendar do
It is an integer from 1 to 366.
## Examples
iex> Jalaali.Calendar.day_of_year(1398, 1, 31)
31
iex> Jalaali.Calendar.day_of_year(-61, 2, 1)
32
iex> Jalaali.Calendar.day_of_year(1397, 2, 28)
59
```elixir
iex> Jalaali.Calendar.day_of_year(1398, 1, 31)
31
iex> Jalaali.Calendar.day_of_year(-61, 2, 1)
32
iex> Jalaali.Calendar.day_of_year(1397, 2, 28)
59
```
"""
@spec day_of_year(year, month, day) :: 1..366
Expand Down
14 changes: 1 addition & 13 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,13 @@ defmodule Jalaali.Mixfile do
]
end

# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
[applications: [:logger]]
end

# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# Type "mix help deps" for more examples and options
defp deps do
[
{:ex_doc, "~> 0.24", only: :dev, runtime: false},
{:ex_doc, "~> 0.28.4", only: :dev, runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}
]
end
Expand Down
10 changes: 5 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%{
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
"earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.25.3", "3edf6a0d70a39d2eafde030b8895501b1c93692effcbd21347296c18e47618ce", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "9ebebc2169ec732a38e9e779fd0418c9189b3ca93f4a676c961be6c1527913f5"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
}

0 comments on commit e2de9ed

Please sign in to comment.