{"id":16656441,"url":"https://github.com/xvw/mizur","last_synced_at":"2025-03-21T16:32:05.701Z","repository":{"id":57536055,"uuid":"87959028","full_name":"xvw/mizur","owner":"xvw","description":"Mizur is a tool to simplify the handling of units, and units coercion/mapping. (it is an evolution of Abacus)","archived":false,"fork":false,"pushed_at":"2018-01-15T03:28:13.000Z","size":237,"stargazers_count":35,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-13T09:57:30.215Z","etag":null,"topics":["elixir","macros","metrics","subtype","typesafe"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xvw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-11T17:01:40.000Z","updated_at":"2023-09-01T08:49:26.000Z","dependencies_parsed_at":"2022-08-29T00:41:24.688Z","dependency_job_id":null,"html_url":"https://github.com/xvw/mizur","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvw%2Fmizur","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvw%2Fmizur/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvw%2Fmizur/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xvw%2Fmizur/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xvw","download_url":"https://codeload.github.com/xvw/mizur/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221817062,"owners_count":16885455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","macros","metrics","subtype","typesafe"],"created_at":"2024-10-12T09:57:20.175Z","updated_at":"2024-10-28T10:29:31.988Z","avatar_url":"https://github.com/xvw.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mizur\nPronounced `/'meʒə/`\n\n**Mizur** is a tool to simplify the management, conversion  \nand mapping of units. \nThe manipulation of measurement units should (at best) \nbe typesafe.\n\n![Mizur Logo](images/logo.png)\n(A special thanks to [@fh-d](https://github.com/fh-d) for this awesome logo !)\n\n- [Presentation](#content)\n- [Some examples](#some-examples)\n- [Installation](#installation)\n- [Special thanks](#special-thanks)\n\n## Some examples\n\n### Basic example\n\nDefinition of a metric system for computing distances :\n\n```elixir \n\ndefmodule Distance do \n  use Mizur.System\n  type m\n  type cm = m / 100 \n  type mm = m / 1000 \n  type km = m * 1000\nend\n\n```\nUsing this module provides the following functions:\n\n-  `Distance.m/0` : to reference the type `Distance.m`\n-  `Distance.cm/0` : to reference the type `Distance.cm`\n-  `Distance.mm/0` : to reference the type `Distance.mm`\n-  `Distance.km/0` : to reference the type `Distance.km`\n\nand : \n\n-  `Distance.m/1` : to create packed values in the `Distance.m` type\n-  `Distance.cm/1` : to create packed values in the `Distance.cm` type\n-  `Distance.mm/1` : to create packed values in the `Distance.mm` type\n-  `Distance.km/1` : to create packed values in the `Distance.km` type\n\nand sigils : `Distance.sigil_t(value, ['typename'])`.\n\n#### Example of common Mizur usage\n\n```elixir\na = Distance.m(200)\nb = Distance.cm(200)\nresult = Mizur.add(a, b)\nassert result = Distance.m(202)\n```\n\n### Using infix notation\n\nYou can use infix notation for operations on units of measurements \nusing `use Mizur.Infix`.\n\nAs with the `import` directive, you can use the `:except` and `:only` parameters \n(exactly in the same way as using` import`).\n\nThe main difference with `import` is that `use` will overwrite the correct \noperators of the `Kernel` module.\n\n\n### Manage arithmetic operations on datetime\n\n```elixir \ndefmodule MyTime do \n\n  use Mizur.System\n  type sec\n  type min  = sec * 60 \n  type hour = sec * 60 * 60\n  type day  = sec * 60 * (60 * 24)\n\n  def now do \n    DateTime.utc_now()\n    |\u003e DateTime.to_unix(:second)\n    |\u003e sec()\n  end\n\n  def new(year, month, day, hour, min, sec) do\n    ndt = NaiveDateTime.new(year, month, day, hour, min, sec) \n    case ndt do \n      {:error, message} -\u003e raise RuntimeError, message: \"#{message}\"\n      {:ok, value} -\u003e\n        DateTime.from_naive!(value, \"Etc/UTC\")\n        |\u003e DateTime.to_unix(:second)\n        |\u003e sec()\n    end\n  end\n\n  def to_datetime(value) do \n    elt = Mizur.from(value, to: sec())\n    int = round(Mizur.unwrap(elt))\n    DateTime.from_unix!(int) #beurk, it is unsafe\n  end\n  \nend\n\nuse Mizur.Infix, only: [+: 2, -: 2]\nimport MyTime\n\n# Create a typed_value of the current timestamp:\na = now()\n\n# Add two days and four hour\nb = a + ~t(2)day + ~t(4)hour # I use Sigils... \n\n# Sub ten minuts \nc = b - ~t(10)min\n\n# Convert into DateTime \nresult = to_datetime(c)\n```\n\n### Other examples\n\nThe test module gives many usage examples :\n[Test module](https://github.com/xvw/mizur/blob/master/test/mizur_test.exs)\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `mizur` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:mizur, \"~\u003e 0.1.1\"}]\nend\n```\n\n## Special Thanks\n\n- [@julien-leclercq](https://github.com/julien-leclercq), a lot of help about unit-comprehension\n- [@Fenntasy](https://github.com/Fenntasy), help for the design\n- [@fh-d](https://github.com/fh-d), for the logo\n- [@tgautier](https://github.com/tgautier) and the LilleFP team !\n\nDocumentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)\nand published on [HexDocs](https://hexdocs.pm). Once published, the docs can\nbe found at [https://hexdocs.pm/mizur/readme.html](https://hexdocs.pm/mizur/readme.html).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxvw%2Fmizur","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxvw%2Fmizur","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxvw%2Fmizur/lists"}