Giter Site home page Giter Site logo

momento's Introduction

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.

momento's People

Contributors

mathewdgardner avatar vishaldeepak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

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.