« Back

# stringdate

## Rationale

Stringdate was created to cut down usage of the javascript Date object in the front end.
We noticed in a lot of situations, dates come in from the back-end as a string, are represented to the user as a string, and then sent to the back as a string. Lots of buggy code was dedicated to parsing and stringifying dates just to do simple manipulations.
I created this library so dates could stay as ISO strings all the way from the backend to the user.

## Shortcomings

  • It doesn't deal with times - I tried really hard to implement them but it got really messy really fast. Locking it down to just dates made the library small and manageable. Time is tricky, there is a reason there are so many new javascript date libraries.
  • Formatting is based of date-fns - Just for speed of development and because it was already a dependency of our apps at the time, I used date-fns for formatting. This brings a quite large chunk of code a long for the ride that I'm pretty sure is not used.

## Samples

yarn add stringdate
import {add, format} from 'stringdate';

const today = '2020-01-01';
const tomorrow = add('P1D')(today); // 2020-01-01
const output = format('MMMM do yyyy')(tomorrow); // 'January 2nd 2020';