A handful of date utilities used on Slay.
Install package:
# npm
npm install @slay-pics/date-utils
# yarn
yarn add @slay-pics/date-utils
# pnpm
pnpm install @slay-pics/date-utils
# bun
bun install @slay-pics/date-utils
addYears(date, amount)
addMonths(date, amount)
addDays(date, amount)
addHours(date, amount)
addMinutes(date, amount)
addSeconds(date, amount)
Adds the specified amount of units to a date. Date can be a string, a JS date or null. If null is passed, then the current date is used.
isPast(date)
isFuture(date)
Determines if the given date occurs in the past or future.
isWithinYears(date, amount)
isWithinMonths(date, amount)
isWithinDays(date, amount)
isWithinHours(date, amount)
isWithinMinutes(date, amount)
isWithinSeconds(date, amount)
Determines if the specified date is within the given range of the current date.
dayDiff(date1, date2)
Returns the difference between two dates in days
thisMonth(date)
Returns a date that is the 1st day of the month of the specified date.
previousMonth(date)
Returns a date that is the 1st day of the prior month of the specified date.
nextMonth(date)
Returns a date that is the 1st day of the next month of the specified date.
Published under MIT License.