Giter VIP home page Giter VIP logo

iso8601's Introduction

iso8601

Build Status Tag Erlang Version Downloads

An ISO 8601 date formatting and parsing library for Erlang

iso8601 project logo

Contents

About

The erlang_iso8601 library was originally created by Sean Sawyer in 2011. In 2016, Sean handed off maintenance of the library to the erlsci Github org at which point the project (and repo) was renamed to simply iso8601, matching its Erlang app name:

  • git clone https://github.com/erlsci/iso8601.git

Thanks to Github's forwarding for project renames and moves, the following still work:

  • git clone https://github.com/seansawyer/erlang_iso8601.git
  • git clone https://github.com/erlsci/erlang_iso8601.git

Usage

Add it to your rebar.config deps:

{iso8601, {git, "https://github.com/erlsci/iso8601.git", {tag, "1.3.2"}}}

Format a timestamp or calendar datetime tuple:

1> iso8601:format(now()).
<<"2012-02-16T01:06:19Z">>
2> iso8601:format(calendar:universal_time()).
<<"2012-02-16T01:06:48Z">>

Parse a date string or binary:

3> iso8601:parse(<<"2012-02-16T01:06:48Z">>).
{{2012,2,16},{1,6,48}}
4> iso8601:parse("2012-02-16T01:06:48Z").
{{2012,2,16},{1,6,48}}

Add 1 hour, 2 minutes and 3 seconds to a datetime tuple:

5> Datetime = iso8601:parse(<<"2012-02-16T01:06:48Z">>).
{{2012,2,16},{1,6,48}}
6> iso8601:add_time(Datetime, 1, 2, 3).
{{2012,2,16},{2,8,51}}

Subtract 1 hour, 2 minutes and 3 seconds from a datetime tuple:

5> Datetime = iso8601:parse(<<"2012-02-16T01:06:48Z">>).
{{2012,2,16},{1,6,48}}
6> iso8601:subtract_time(Datetime, 1, 2, 3).
{{2012,2,16},{0,4,45}}

Fractional times:

7> iso8601:parse("20120203T040506.50").
{{2012,2,3},{4,5,7}}
8> iso8601:parse_exact("20120203T040506.50").
{{2012,2,3},{4,5,6.50}}

Parse durations:

9> iso8601:parse_duration("+P6Y3M1DT1H1M1.1S").
[{sign, "+"}, {years, 6}, {months, 3}, {days, 1}, {hours, 1}, {minutes, 1}, {seconds, 1}]
10> iso8601:parse_duration("PT6M").
[{sign, []}, {years, 0}, {months, 0}, {days, 0},{hours, 0}, {minutes, 6}, {seconds, 0}]

Known Deficiencies

  • Does not support expanded year representation.
  • Does not support intervals.

See the open issues for more info.

Donating

A donation account for supporting development on this project has been set up on Liberapay here:

You can learn more about Liberapay on its Wikipedia entry or on the service's "About" page.

License

The MIT License (MIT)

Copyright © 2011-2014, Sean Sawyer
Copyright © 2012, Tristan Sloughter
Copyright © 2016-2021, Erlang-Aided Enrichment Center

iso8601's People

Contributors

amilkr avatar asakura avatar aseigo avatar fabiankrol avatar getong avatar hachreak avatar kianmeng avatar loguntsov avatar oubiwann avatar paulo-ferraz-oliveira avatar seansawyer avatar stonecypher 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iso8601's Issues

Doesn't compile in Erlang 18.0

I get the following error:

$ rebar compile
==> iso8601 (compile)
src/iso8601.erl:17: type tuple(_,_,_) undefined
src/iso8601.erl:224: type tuple(_,_) undefined
Compiling src/iso8601.erl failed:
ERROR: compile failed while processing /Users/oubiwann/lab/lfe/lupyter/deps/iso8601: rebar_abort

In Erlang 17.5, it compiles just fine:

$ rebar compile
==> iso8601 (compile)
Compiled src/iso8601.erl

Release request

Would it be possible to tag a release, here and in Hex.pm?

Many thanks.

Version error in the documentation

On the readme it says:

Add it to your rebar.config deps:

{iso8601, ".*", {git, "https://github.com/erlsci/iso8601.git", {tag, "1.2.0"}}}
Or for rebar3:

{iso8601, {git, "https://github.com/erlsci/iso8601.git", {tag, "1.2.0"}}}

When the version string should be "1.2".

Continue to support rebar2

Right now, only rebar3 is being used on Travis CI. It would be good to make sure we're not breaking anything with rebar2 users. We can do this with Travis CI environments ...

This library uses types that are not exported by Erlang's calendar module

In particular, when running dialyzer, these warnings are generated:

   0: Unknown type calendar:hour/0
   0: Unknown type calendar:minute/0
   0: Unknown type calendar:second/0

Looking at calendar.er, it seems that only the following types are exported:

-export_type([date/0, time/0, datetime/0, datetime1970/0]).

Might have to just redefine calendar's private types in this lib ...

Support erlang.mk

There have been multiple requests for erlang.mk support, including the following PRs:

The second two were closed as duplicates, and the first one was closed due to the original author moving on (there was a multi-year response lag from the maintainers). All the PRs offered something a little different, so whoever picks up this ticket may want to refer to them (and the associated comments) for insight.

I do not know erlang.mk, so we'll need to have some collaboration here :-)

Some notes from those PRs:

  • we don't want to include erlang.mk in this project -- but!
  • we can create a Makefile with a target that will download the latest erlang.mk when an erlang.mk target is run
  • we'll need to update .travis.yml to add an environment for testing builds (and running tests) using erlang.mk on Travis

Bad result for truncation of seconds.

iso8601:parse("2018-03-07T14:15:59.966033Z").
{{2018,3,7},{14,15,60}}

I have this result for 1.3 tag version of this library.
I think it is wrong.

Library must ignore fractional part of the seconds.

Module not compiling when a dependency

I've got a project where erlang_iso8601 is a dependency (in the project's rebar.config file). When running rebar compile, only the .app.src and unit test file get compile and placed in the ./deps/iso8601/ebin directory:

$ ls -al deps/iso8601/ebin/
total 48
drwxr-xr-x   4 oubiwann  staff    136 Sep  6 15:45 .
drwxr-xr-x  10 oubiwann  staff    340 Sep  6 15:43 ..
-rw-r--r--   1 oubiwann  staff    262 Sep  6 15:45 iso8601.app
-rw-r--r--   1 oubiwann  staff  20244 Sep  6 15:45 iso8601_tests.beam

In order to compile the iso8601.beam file, I have to switch to deps/iso8601 and run rebar compile in that dir.

Microsecond precision

This will need to be a major version bump, since the time() type will have to change to accomodate microseconds.

Images stored in 'priv' directory.

The priv/images directory contains logos referenced in the README. The priv directory is usually used for storing data required to run the software, so the rebar tool includes content of the priv directory in a binary release (whereas the README.md itself is not included). The 3MB image (logo-large) makes the binary release file unnecessarily large, becase the logos aren't really required at run-time.

Would it be possible to store the images in some other directory e.g. doc/images? It wouldn't impact anything (I guess) and my release package would get significantly smaller.

Timezone is parsed in reverse

iso8601:parse(<<"2012-07-03T18:49:23-0400">>).

It should return {{2012,7,3},{22,49,23}} but it returns {{2012,7,3},{14,49,23}}.

Fix it now, jerk!

Move from Travis CI to GitHub Actions?

Would you be interested in a pull request that moves CI from Travis CI to GitHub Actions, or at least adds GitHub Actions alongside Travis CI? It seems travis-ci.org will stop being useful from Dec 31 2020. I can do it, except that I think you need to create the workflow yml, first, in master, after which I can branch off of.

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.