GithubHelp home page GithubHelp logo

edtfy's Introduction

edtfy (bring your own pronunciation)

Circle CI

edtfy is a parser that transforms user input into the edtf format.

Install

npm install edtfy   #npm
bower install edtfy #bower

Usage

parse

edtfy = require('edtfy');
edtfy.locale('fr');
edtfy('29 mars 1988'); // 1988-03-29

locale

edtfy.locale(locale): define the locale

edtfy.locale(): retrieve the locale

Compatibility

Level 0

5.1.1 Date

input output
2008 2008
december 1988 2008-12
02/03/1988 2001-02-03

5.1.2 Date and Time

Not supported for now.

5.1.3 Interval

input output
from 1964 to 2008 1964/2008
June 2004 - August 2008 2004-06/2008-08
2/1/2004 / 2/8/2005 2004-02-01/2008-02-08
02/01/2004-2005 2004-02-01/2005
from 2005 to June 2006 2005/2006-02

Level 1

5.2.1 Uncertain/Approximate

input output
1984? 1984?
June 2004? 2004-06?
June the 11th, 2004? 2004-06-11?
around 1984 1984~
about 1984? 1984?~

5.2.2 Unspecified

input output
199u 199u
1999-uu 1999-uu
1999-01-uu 1999-01-uu
1999-uu-uu 1999-uu-uu

5.2.3. Extended Interval (L1)

input output
from 06/01/2004 to unknown 2004-06-01/unknown
from 01/01/2004 to open 2004-01-01/open
from around 1984 to June 2004 1984~/2004-06
1984 - around June 2004 1984/2004-06~
1984? - ~2004? 1984?/2004?~

5.2.4 Year Exceeding Four Digits (L1)

input output
170000002 y170000002
-170000002 y-170000002

5.2.5 Season

input output
Spring 2001 2001-21

Level 2

5.3.1 Partial Uncertain/Approximate

Not supported for now.

5.3.2 Partial Unspecified

input output
12/25/156u 156u-12-25
12/25/156uu 15uu-12-25
12/uu/15uu 15uu-12-uu
uu/25/1560 1560-uu-25

5.3.3 One of a Set

The .. feature is only supported of before and after for now.

input output
1667 or 1668 or 1670 [1667,1668,1670]
Jan 1760 or Feb 1760 or December 1760 [1760-01,1760-02,1760-12]
1667 or 12/1760 [1667,1760-12]
before 1930 [..,1930]
after march 2004 [2004-03,..]

5.3.4 Multiple Dates

The .. feature is not supported for now.

input output
1667 and 1668 and 1670 {1667,1668,1670}
1960 and December 1961 {1960,1961-12}

5.4.5 Masked Precision

input output
196x 196x
19xx 19xx

5.3.6 Extended Interval (L2)

Not supported for now.

License

MIT © Nicolas Barbotte

edtfy's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar nicompte avatar stevetweeddale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

edtfy's Issues

EDTF output

Thank you for this amazing work, especially the i18n aspect of it.

As EDTF is typically used for storage, I think most users will also need the API to output the human-readable display of such EDTF data on the client/browser side. Do you plan that feature?

Thanks.

Issue with dashes vs slashes for Level 0 YYYY-MM dates

In doing some more testing (and confirming on your website), I found some unexpected behavior with using dashes vs. slashes for separating Level 0 dates of the form YYYY-MM:

For instance:
2000 => 2000 (great!)
2001-12 => 2001/12 (unexpected since / are not allowed)
2001/12 => error/could not be parsed (would have expected 2001-12)

certain valid inputs throw syntax error

Super work on this parser -- it's extremely handy!

I'm getting a syntax error when passing certain valid dates that meet edtf standards and was wondering if this was expected behavior (and if you have a suggested way for me to handle this while still catching "real"/un-parseable errors).

For instance:
If a user inputs "1892", edtfy returns the string with no error (=great!).

If a user inputs "around 1892", edtfy returns 1892~ (=awesome!).

If a user inputs "1892~", edtfy throws:

peg$SyntaxError {message: "Expected " ", " / ", " A ", " B2 ", " C", " O ", "…", "u", "x", [0-9]
or end of input but "~" found.", expected: Array[13], found: "~",
location: Object, name: "SyntaxError"}

which I didn't expect (I was expecting it to just pass the string back to me).

Similarly, if a user inputs "open", it throws a similar peg error:

peg$SyntaxError {message: "Expected " ", " / ", " A ", " B2 ", " O ", "*", "-…, [0-9], [ivxlcdm]
or end of input but "O" found.", expected: Array[22], found: "O",
location: Object, name: "SyntaxError"}

I checked with "1892?" and edtfy passes the string back to me, which was what I was expecting with "1892~".

Am I missing something? Thanks!

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.