1.2.1 • Published 5 years ago

momentium v1.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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

You are welcome to contribute by following the usual Github route where issues and requests are also welcome.


Here is a simple scenario of why this package was firstly needed, beyond the above helpers:

alt text

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.

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago