Japanese era-converter for elixir
If available in Hex, the package can be installed
by adding ex_wareki
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_wareki, "~> 1.0.0"}
]
end
ExWareki provides some parsing algorithm for Japanese date format.
iex> ExWareki.Parser.parse_wareki("令和元年九月十三日")
{:ok, %ExWareki.Structs.Wareki{name: "令和", yomi: "れいわ", year: 1, month: 9, day: 13}}
iex> ExWareki.Parser.parse_seireki("2019年9月15日")
{:ok, %ExWareki.Structs.Seireki{year: 2019, month: 9, day: 15}}
iex> ExWareki.Parser.parse_seireki("二千十九年九月十五日")
{:ok, %ExWareki.Structs.Seireki{year: 2019, month: 9, day: 15}}
iex> ExWareki.Parser.parse_seireki("2019-9-15")
{:ok, %ExWareki.Structs.Seireki{year: 2019, month: 9, day: 15}}
Also, a converter is useful to transform date into another format.
You can convert an date formatted by Japanese era (wareki) into A.D. one (seireki):
iex> ExWareki.Era.wareki2seireki(%ExWareki.Structs.Wareki{name: "平成", yomi: "へいせい", year: 1, month: 2, day: 13})
{:ok, %ExWareki.Structs.Seireki{year: 1989, month: 2, day: 13}}
You can also convert an date formatted by A.D. era (seireki) into Japanese one (wareki):
iex> ExWareki.Era.seireki2wareki(%ExWareki.Structs.Seireki{year: 1989, month: 2, day: 13})
{:ok, %ExWareki.Structs.Wareki{name: "平成", yomi: "へいせい", year: 1, month: 2, day: 13}}
本ツールで使用している元号は、以下のソースを基にしています。 近代を除く元号は、研究によって上書きされ得ることにご留意ください。
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request