epok
- Epok extends Date() functionality with easy to use functions and Chai-like syntax
- No external dependencies
- Since this is just a wrapper around Date(), all leap year calculations are taken care of for you
Installation
npm install epok
Usage
// 2016-06-29T07:30:00.000Znow // 2016-06-29T07:40:00.000Zfromnow // 2016-06-29T07:20:00.000Zago // 600000tomilliseconds // 2016-06-30T11:50:00.000Zfromnow // 2018-10-03T05:00:00.000Zfrom
API
Epok()
Creates a Date
that defaults to the current date a time.
// Default // With Optional Offset date // or
now
Returns the current date
now
from
Used in conjunction with now
or date
to return a Date
from the specified date/time
// Return the date 1 day from nowfromnow // Return the date 1 day from 6/29/2016from
date
Used in conjunction with from
to return a Date
from the specified date/time
// Defaults to the current date if no date is specifiedfrom // You can use a string representation of the datefrom // Or you can pass a Date() objectfrom
ago
Returns the Date
from some time ago
// Return the date 1 day agoago // Return the date 1 day ago from 6/29/2016ago
to
Used in conjunction with milliseconds
and seconds
to return the duration in milliseconds or seconds. See milliseconds
and seconds
for usage.
milliseconds
Returns the specified duration in milliseconds
// Return 10 minutes in millisecondstomilliseconds // Return 1 year, 2 days and 3 hours in millisecondstomilliseconds
NOTE: Months cannot be converted to milliseconds currently because of the varying days in a month. This functionality is planned for the future.
seconds
Returns the specified duration in seconds
// Return 10 minutes in secondstoseconds // Return 1 year, 2 days and 3 hours in secondstoseconds
NOTE: Months cannot be converted to seconds currently because of the varying days in a month. This functionality is planned for the future.
minutes
Specify the number of minutes to be used in the duration or date calculation. minutes
can be chained with other time functions. E.g. hours
days
weeks
months
years
See example below
// Return the date 10 minutes from nowfromnow // Return 10 minutes in millisecondstomilliseconds // Return the date 2 days, 3 hours, and 24 minutes from nowfromnow
hours
Specify the number of hours to be used in the duration or date calculation. hours
can be chained with other time functions. E.g. minutes
days
weeks
months
years
See example below
// Return the `Date` 10 hours from nowfromnow // Return 10 hours in millisecondstomilliseconds // Return the `Date` 2 days, 3 hours, and 24 minutes from nowfromnow
days
Specify the number of days to be used in the duration or date calculation. days
can be chained with other time functions. E.g. minutes
hours
weeks
months
years
See example below
// Return the `Date` 10 days from nowfromnow // Return 10 days in millisecondstomilliseconds // Return the `Date` 2 days, 3 hours, and 24 minutes from nowfromnow
weeks
Specify the number of weeks to be used in the duration or date calculation. weeks
can be chained with other time functions. E.g. minutes
hours
days
months
years
See example below
// Return the `Date` 10 weeks from nowfromnow // Return 10 weeks in millisecondstomilliseconds // Return the `Date` 2 years, 3 months, and 22 weeks from nowfromnow
months
Specify the number of months to be used in the duration or date calculation. months
can be chained with other time functions. E.g. minutes
hours
days
weeks
years
See example below
// Return the `Date` 10 months from nowfromnow // Return 10 months in millisecondstomilliseconds // Return the `Date` 2 years, 3 months, and 22 weeks from nowfromnow
years
Specify the number of years to be used in the duration or date calculation. years
can be chained with other time functions. E.g. minutes
hours
days
weeks
years
See example below
// Return the `Date` 10 years from nowfromnow // Return 10 years in millisecondstomilliseconds // Return the `Date` 2 years, 3 months, and 22 weeks from nowfromnow
isLeapYear([year])
Takes a year and returns true
if it is a leap year and false
otherwise
// true // false // true