Skip to content

mathewdgardner/momento

Repository files navigation

Momento

master coverage docs MIT licensed hex gitter

Momento is an Elixir port of Moment.js for the purpose of parsing, validating, manipulating, and formatting dates.

Getting started

Installation

Available in Hex, the package can be installed as:

  1. Add momento to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:momento, "~> 0.1.1"}]
end
```
  1. Ensure momento is started before your application:
```elixir
def application do
  [applications: [:momento]]
end
```

Usage

> import Momento
> datetime = date!
%DateTime{calendar: Calendar.ISO, day: 1, hour: 20, microsecond: {904217, 6},
 minute: 44, month: 7, second: 32, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2016, zone_abbr: "UTC"}

> date! |> add(5, :years)
%DateTime{calendar: Calendar.ISO, day: 1, hour: 20, microsecond: {730106, 6},
 minute: 45, month: 7, second: 57, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2021, zone_abbr: "UTC"}

> date! |> add(5, :years) |> add(8, :months)
%DateTime{calendar: Calendar.ISO, day: 1, hour: 20, microsecond: {32939, 6},
 minute: 46, month: 1, second: 24, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2022, zone_abbr: "UTC"}

> date! |> subtract(1, :days) |> subtract(3, :hours) |> add(15, :minutes)
%DateTime{calendar: Calendar.ISO, day: 0, hour: 18, microsecond: {164079, 6},
 minute: 4, month: 7, second: 13, std_offset: 0, time_zone: "Etc/UTC",
 utc_offset: 0, year: 2016, zone_abbr: "UTC"}

> date! |> format("YYYY-MM-DD")
"2016-07-01"

> date! |> format("x")
"1467406270"

Roadmap

Things that need to be added for this library to be most useful:

  1. Implement more format tokens
  2. Add timezone support
  3. Implement leaps
  4. Localization
  5. Other useful Moment.js things

Contributing

Making a date time library is a tall order. I need help if we are going to make this work. I started this project in an effort to learn Elixir so I'm sure there are many improvements in the existing codebase that can be made. There are probably bugs and generally bad Elixir patterns. I also place TODO:s everywhere so feel free to tackle them or any Enhancement/Bug issues.

License

This software is licensed under the MIT license.

About

moment.js implemented in Elixir

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages