momentium
JavaScript Date() helper for NodeJS or the Browser.
Though it contains some handy display helpers from Date() object or Date() as string, this package was initially purposed to assess the need of the exact date and time from a client machine, avoiding the timezone offset when you try something like new Date().toJSON()
and get UTC adjusted results though in Date() object the date and time was correctly displayed.
Installation
npm install momentium --save
Usage
var momentium = require('momentium');
or
import momentium from 'momentium';
or
import {
niceDateAndTimeFromObject,
niceDateFromString,
// and others
} from 'momentium';
Helpers examples:
import {
dateObjectToJSON,
dateStringToObject,
niceDateAndTimeFromObject,
niceDateFromObject,
niceTimeFromObject,
niceDateAndTimeFromString,
niceDateFromString,
niceTimeFromString,
dayOnlyFromObject,
dayAndMonthOnlyFromObject,
dayOnlyFromString,
dayAndMonthOnlyFromString,
dayNameAndDateOnlyFromString,
dayNameAndDateOnlyFromObject
// ...
} from 'momentium'; // using ES6 import
const dateObj = new Date(); // standard date object
const dateString = dateString(dateObj); // string (yyyy-mm-ddThh:mm...)
dateObjectToJSON(new Date()) // => solves .toJSON() timezone offset. See ilustration at the end of document.
dateStringToObject(dateString) // => converts yyyy-mm-ddThh:mm... back to a Date object
niceDateFromObject(dateObj) // => dd/mm/yyyy
niceDateAndTimeFromObject(dateObj) // => dd/mm/yyyy hh:mm
niceDateAndTimeFromString(dateString) // => takes a yyyy-mm-ddThh:mm... string date and returns dd/mm/yyyy hh:mm
Wherever you have time involved, you can pass true as second parameter and seconds will also be included:
niceTimeFromString(dateString, true) // => hh:mm:ss
issues and requests are also welcome.
You are welcome to contribute by following the usual Github route whereHere is a simple scenario of why this package was firstly needed, beyond the above helpers:
There might be better solutions to this out there, but I couldn't find a simple and tiny solution, hence this simplified small piece of code got here.