README
Date-manipulator
This is a simple date and time manipulator. Using this package you can get some helpful features like finding difference between dates, and getting current date and time by passing a string. More features are being developed by our team.
Installation
Install this package via npm:
npm install @aimu/date-manipulator
This package is also available on unpkg, so you can load it via script tag:
<script src="https://unpkg.com/@aimu/date-manipulator"></script>
<script>
// You can use library features here.
</script>
Usage
Input
You can pass any valid arguments of Date() built-in javascript object.
You can also pass options as object, right now, there's only one option available: hFormat: 12 or 24 as string value (It's 24 by default).
Example:
var d = new dateM({
hFormat: '12',
});
console.log(d.current('dd-mm-yyyy hh:mm')); // Prints current date and time format in 12 hours.
Methods
dateM().current()
This method returns a string replaced by a requested values.
var d = new dateM();
// dd - date, mm - month, yyyy - year.
// You can also get month and day as string value by passing day or month.
// Note: time representing characters must be separated by colon(:).
// hh:mm:ss - OK
// hh mm ss - Warning: You may don't get what you expect.
// Example:
d.current('dd-mm-yyyy hh:mm:ss'); // Prints current date and time.
d.current('day, month yyyy'); // Prints day & month strings, and year.
dateM().unixTime()
This method returns unix time in miliseconds.
dateM.timePassed()
Using this method you can get difference between two dates in days.
Note: Arguments should be dateM objects.
Example:
var b = new dateM(2020, 0, 1);
var e = new dateM(2021, 0, 1);
console.log(dateM.timePassed(b, e)); // Prints 366
To-do list
- Adding timezone option.
- Validation of arguments.
- Error handling.
- String values for day and month.
- Creating a meaningful and helpful documentation.
- Adding some options for timePassed method.
- Adding some more features.
Ofcourse, there's a lot to-do.
Contributing
Thank you for considering contributing to our project.
Here are instructions for contributing.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request.
Working on your first Pull Request?
You can learn how from this free series How to Contribute to an Open Source Project on GitHub