1.2.0 • Published 1 year ago

@arwinvdv/datetime v1.2.0

Weekly downloads
-
License
GPL-2.0-or-later
Repository
github
Last release
1 year ago

@arwinvdv/datetime

npm version

This package does not need to be installed if you are using @arwinvdv/bundle.

DateTime library for easepick.

Documentation

https://easepick.com/packages/datetime

DateTime() constructor

Creates a JavaScript DateTime instance that represents a single moment in time. Using: new DateTime(date, format, lang)

argumenttypedefault valuedescription
dateDate string numbernullDate object or date string or number (unix timestamp).
formatstring'YYYY-MM-DD'Required when you provide date argument as string. Must match a string value for proper parsing.
langstring'en-US'Affects month names (MMM, MMMM tokens).

You can omit all arguments and call new DateTime(). This will create a DateTime object represents the current date.

Methods

nameargumentsdescription
getWeek-Returns a week number of date
clone-Returns a copy of date
toJSDate-Returns Date object.
inArray(array, inclusivity)Find DateTime object in passed DateTime array.
isBetween(date1, date2, inclusivity)Check if a DateTime is between two other DateTime.
isBefore(date, unit)Check if a DateTime is before another DateTime. unit are day, month, year.
isSameOrBefore(date, unit)Check if a DateTime is before or the same as another DateTime. unit are day, month.
isAfter(date, unit)Check if a DateTime is after another DateTime.. unit are day, month, year.
isSameOrAfter(date, unit)Check if a DateTime is after or the same as another DateTime. unit are day, month.
isSame(date, unit)Check if a DateTime is the same as another DateTime. unit are day, month.
add(duration, unit)Mutates the original DateTime by adding unit. unit are day, month.
subtract(duration, unit)Mutates the original DateTime by subtracting unit. unit are day, month.
diff(date, unit)Returns diff between two DateTime. unit are day, month.
format(format, lang)Format output. See tokens format for format argument. lang affects month names (MMM, MMMM tokens).

Tokens format

Tokens are case-sensitive.

TokenOutput
Day of MonthD1 2 … 30 31
DD01 02 … 30 31
MonthM1 2 … 11 12
MM01 02 … 11 12
MMMJan Feb … Nov Dec
MMMMJanuary February … November December
YearYY70 71 … 29 30
YYYY1970 1971 … 2029 2030
Hours (24 hour time)H0 1 … 22 23
HH01 02 … 22 23
Minutesm1 2 … 58 59
mm01 02 … 58 59
Secondss1 2 … 58 59
ss01 02 … 58 59