Skip to content

histograph/fuzzy-dates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuzzy Dates

Build Status

Fuzzy dates module for Histograph.

Input

One of the following:

  • ISO 8601 date string (YYYY-MM-DD):

"2007-06-12"

  • Single year (string or number):

1920, "1995"

  • Object with a ISO 8601 date string and an error specification:
{
  date: '1962-10-10',
  error: '1M'
}
  • Object with a year string/number and an error specification:
{
  date: '1970',
  error: '5y'
}
  • String with year and error in years, of the form :year±:error:

"1995±5"

  • Array of two years
[
  1930,
  1940
]
  • Array of two ISO 8601 date strings
[
  "1912-03-04",
  "1912-03-26"
]

Error specification

{
  date: '1970',
  error: '1M'
}
  • Date: either a year or an ISO 8601 date
  • error units:
    • d: day
    • M: month
    • y: year

Fuzzy Dates uses Moment.js time shorthand keys (currently only days, months and years).

Output

  • Array of two ISO 8601 dates

Example

Input:

{
  year: 1915,
  error: '3y'
}

Output:

[
  '1912-01-01',
  '1918-12-31'
]

See test/testDates.js for more examples, or run npm test.

Installation

npm install --save histograph/fuzzy-dates

Usage

var fd = require('fuzzy-dates');

var a = fd.convert('1995');

console.log(a); // => ["1995-01-01", "1995-12-31"]

Copyright (C) 2015 Waag Society.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published