What is pretty-easy-dates?
$ npm install pretty-easy-dates --save
--save flag is used to save the module as a project dependancy in your package.json file.
After installing the module (localy in your project directory), in order to use it in your file you first need to require it.
let prettyDate = ;
or if you use TypeScript
- if a parameter passed is a string, it needs to be a valid representantion of a date; something in the line of :
- 'Mar 29 2017',
- 'March 29 2017',
- 'Wed Mar 29 2017',
- 'Wed Mar 29 2017 15:33:51 GMT+0200 (CEST)'
- you can use one of the following symbols, as a MM DD YYYY separator:
- . (dot),
- , (comma),
- (blank space),
- / (slash),
- - (dash),
- _ (underscore)
- month and date values can be passed as either one or two digit notation, whereas year value must be a four digit notation.
; // from instance of Date class; // from String representation of date
The module returns the hash with the following properties
Consider the following
The module will return an instance of an Error class, if argument passed is not a valid date value, instead of throwing an error and terminating the Node process thus making it more dynamic and usable in production.
Having this in mind, I advise you to consider including a utility library to check the output data type, such as pretty-easy-data-types.
/** Only import the checks you will be using,* instead of including the whole library*/constisError // check for instance of Error class} = ;const prettyDate = ;// You can pass any value/data type to a function// without causing your process to breakconst isThisValidDate = ;/** After converting the date to its' corresponding hash* you should perform the check on the value returned to see* if the conversion was successful.** If the value returned is of type Object the conversion was successful* and in this example we're going to extract the date and time from it* else it is an instance of an Error class and we're just going to get it's message*/const dateAndTime = ! ? isThisValidDatenow : isThisValidDatemessage;
The module follows the Semantic Versioning standard to communicate what kinds of changes are introduced in the new releases.
Patch releases : n.n.X -> Bug fixes, documentation updates, code cleanups, new test cases, optimization stuff and other minor changes that you should probably not be aware of;
Major releases : X.n.n -> Changes that could possibly introduce the backwards compatibility issues. These are however very rare and could be relevant to you only in the case of an endpoint API change and the way you communicate with the module.
03/30 - v1.0.1
- Documentation updates
03/30 - v1.0.0
- Initial release
Want to contribute?
Great! Anyone can help make this project better - check out the github repository!
Found a bug?
Please open a an issue.
Copyright (c) 2017 Ognjen Jevremović
Licensed under the MIT License.