Skip to content

A simple JavaScript utility to convert various value to a Date.

License

Notifications You must be signed in to change notification settings

hypersoftllc/qc-to_date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qc-to_date

Build Status Coverage Status License Downloads

npm badge

A simple JavaScript utility to convert various values to a Date.

Installation

npm install --save qc-to_date

Example Usage

import { toDate, toDateOrNull } from 'qc-to_date';

toDate(946684800000);   // Date on 2000-01-01T00:00:00.000 UTC
toDate(new Date());     // The Date input

// Returns the Date created from the number returned from `toDate`.
toDate({ toDate() { return 946684800000; } });

// Returns the Date returned from `toDate`.
toDate({ toDate() { return new Date(); } });

toDate(<not-date-like>);                    // The not-date-like input
toDate(<not-date-like>, undefined);         // The not-date-like input
toDate(<not-date-like>, null);              // `null`
toDate(<not-date-like>, 0);                 // `0`
toDate(<not-date-like>, new Date());        // The new Date
toDate(<not-date-like>, { def: {...} });    // The `{...}` object
toDateOrNull(<not-date-like>);              // `null`
toDateOrNull(<date-like>);                  // The Date