fuzzy-dates

Fuzzy dates module for Histograph

Usage no npm install needed!

<script type="module">
  import fuzzyDates from 'https://cdn.skypack.dev/fuzzy-dates';
</script>

README

Build Status

Fuzzy Dates

Fuzzy dates module for Histograph.

Input

One of the following:

  • ISO 8601 date (YYYY-MM-DD, for example 2007-06-12)
  • Year (string or number)
  • ISO 8601 date with error specification
  • Year with error specification
  • Array of two years
  • Array of two ISO 8601 dates

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"]