@giannisclipper/date v1.0.0
A set of functions to handle date values in various shapes
(version 1.0.0)
Functions are grouped into:
set*(), to create various value shapes expressing a date:
setDateObj( value ), a simple object with integer values ({ year:, month:, day: })
setDateArray( value ), an array of integers ( yaer, month, day )
setDateStr( value ), a string in form of 'YYYYMMDD' (where YYYY is for year, MM for month, DD for day)
setDateRepr( value, pattern ) a representation string in form of 'DD/MM/YYYY' (by default but also customizable to other patterns)
setDateDate( value ) an instance of JS Date class
get*(), to evaluate and retrieve the date values from the above shapes:
getDateObj( value ), date values from an object ({ year:, month:, day: })
getDateArray( value ), date values from an array of integers ( yaer, month, day )
getDateStr( value ), date values from a string in form of 'YYYYMMDD'
getDateRepr( value, pattern ), date values from a representation string like 'DD/MM/YYYY'
getDateDate( value ), date values from an instance of JS Date class
op*(), to compare two date values:
opEqualTo( date1, date2 ), the one date should be equal to the other
opNotEqualTo( date1, date2 ), the one date should not be equal to the other
opGreaterThan( date1, date2 ), the first date should be greater than the second
opGreaterThanEqualTo( date1, date2 ), the first date should be greater than or equal to the second
opLessThan( date1, date2 ), the first date should be less than the second
opLessThanEqualTo( date1, date2 ), the first date should be less than or equal to the second
calc*(), to calculate new date or related values:
calcDayOfWeek( date ), the position of a date in the days sequence of the week (from 1 to 7, monday to sunday)
calcDayOfYear( date ), the position of a date in the days sequence of the year (from 1 to 365/366)
calcDateByDayOfYear( day, year ), the date according to a day in the sequence of a year (from 1 to 365/366)
calcDateByDaysAddition( from, days ), the date according to a starting date and a positive or negative number of days to be added
calcWeeksOfRange( from, till ), the weeks according to a range of days that are placed within
count*(), to count date related values
countDaysOfMonth( month, year ), the number of days of a month
countDaysOfYear( year ), the number of days of a year
countDaysOfRange( from, till ), the number of days of a date range including the starting and ending limits
is*(), to validate date related values:
isYear( value ), if a value is an integer expressing a year (by default from 1900 to 2099 but also customizable to other values)
isLeapYear( value ), if a value is an integer expressing a leap year
isMonth( month, year ), if a value is an integer expressing a month (from 1 to 12)
isDate( year, month, day ), if a series of values expressing a date
config.set*(), to customize general parameters:
config.setYearRange( from, till ), the range of valid years (by default from 1900 to 2099)
config.setReprPattern( pattern ), the pattern for the date representation (by default DD/MM/YYYY)
config.get*(), to retrieve general parameters:
config.getYearRange(), the range of valid years
config.getReprPattern(), the pattern for the date representation
Repository here
Documentation here
3 years ago