Datelish

© 2016-2017 Leandro Silva (http://grafluxe.com)
License: MIT

Datelish

Originally written to help work with calendar data, this class helps parse, format, and transform dates. It supports both Node and browser use.

Constructor

new Datelish()

Details
Author
  • Leandro Silva

Methods

(static) currYear():Number

Returns the current year (in four digit format).
Returns
Type
:Number

(static) dateIsAfter(date, isAfterDate):Boolean

Returns a boolean determining whether a given date is after a date.
Parameters
date:Date
The date to check against.
isAfterDate:Date
The date to compare against.
Returns
Type
:Boolean

(static) dateIsBefore(date, isBeforeDate):Boolean

Returns a boolean determining whether given date is before a date.
Parameters
date:Date
The date to check against.
isBeforeDate:Date
The date to compare against.
Returns
Type
:Boolean

(static) dateIsBetween(date, startDate, endDate, includeEndDateopt):Boolean

Returns a boolean determining whether a given date is between two dates.
Parameters
date:Date
The date to check against.
startDate:Date
The start date.
endDate:Date
The end date.
includeEndDate:Boolean = false (optional)
Whether to include the end date.
Returns
Type
:Boolean

(static) dayCount(startDate, endDate):Number

Returns the number of days between two dates.
Parameters
startDate:Date
The start date.
endDate:Date
The end date.
Returns
Type
:Number

(static) daysFromDate(date, n):Date

Returns a number of days before/after a given date.
Parameters
date:Date
The date to check against.
n:Number
The number of days to advance/retract. Use a negative number to go back days.
Returns
Type
:Date

(static) daysPerMonth(month, year):Array

Returns an array of days for a given month of the specified year. Including the year is requied since days change due to leap year.
Parameters
month:Number|String
Expects either a number representing the current month (0-11) or a string with the month name (as either a three letter abbreviation or the full name in American English).
year:Number
Can be formatted as either two digits or four digits.
Returns
Type
:Array

(static) daysTotal(month, year):Number

Returns the total numbers of days in a given month of the specified year. Including the year is requied since days change due to leap year.
Parameters
month:Number|String
Either a number representing the current month (0-11) or a string with the month name (as either a three letter abbreviation or the full name in American English).
year:Number
Can be formatted as either two digits or four digits.
Returns
Type
:Number

(static) fromBigEndian(dateStr):Date

Returns a date from a big-endian formatted string (YYYY/MM/DD).
Parameters
dateStr:String
The date to check against.
Returns
Type
:Date

(static) fromLittleEndian(dateStr):Date

Returns a date from a little-endian formatted string (DD/MM/YYYY).
Parameters
dateStr:String
The date to check against.
Returns
Type
:Date

(static) fromMiddleEndian(dateStr):Date

Returns a date from a middle-endian formatted string (MM/DD/YYYY).
Parameters
dateStr:String
The date to check against.
Returns
Type
:Date

(static) monthAsNames(short):Array

Returns an array of month names.
Parameters
short:Boolean = false
Whether to return full month names or the 3 letter abbreviated versions.
Returns
Type
:Array

(static) monthIndexToName(index, shortopt):String

Returns the name for a given month index (0–11).
Parameters
index:Number
The index to search.
short:Boolean = false (optional)
Whether to return full a month name or the 3 letter abbreviated version.
Returns
Type
:String

(static) monthNameToIndex(month):Number

Returns the index (0–11) for a given month.
Parameters
month:String
The month name (as either a three letter abbreviation or the full name in American English).
Returns
Type
:Number

(static) monthsFrom(startDate, endDate):Array

Returns an array of months from the given dates.
Parameters
startDate:Date
The start date.
endDate:Date
The end date.
Returns
Type
:Array

(static) nextMonth():Date

Returns the next month.
Returns
Type
:Date

(static) now():Date

Returns the today including the current time.
Returns
Type
:Date

(static) prepend0(val):String

Returns a string with a prepended "0" (if the value is less than 10).
Parameters
val:Number|String
The string/number to check against.
Returns
Type
:String

(static) prevMonth():Date

Returns the previous month.
Returns
Type
:Date

(static) toBigEndian(date, divideropt, prepend0opt):String

Returns a date in big-endian format (YYYY/MM/DD).
Parameters
date:Date
The date to check against.
divider:String = "/" (optional)
The character to use as a divider.
prepend0:Boolean = true (optional)
Whether to prepend a "0" if the value is less than the 10.
Returns
Type
:String

(static) today():Date

Returns today.
Returns
Type
:Date

(static) todayIs(date):Boolean

Returns a boolean determining whether a given date is today.
Parameters
date:Date
The date to check against.
Returns
Type
:Boolean

(static) toISO8601(date):String

Returns a date in ISO 8601 format (YYYY-MM-DDThh:mm:ssTZD).
Parameters
date:Date
The date to check against.
Returns
Type
:String

(static) toLittleEndian(date, divideropt, prepend0opt):String

Returns a date in little-endian format (DD/MM/YYYY).
Parameters
date:Date
The date to check against.
divider:String = "/" (optional)
The character to use as a divider.
prepend0:Boolean = true (optional)
Whether to prepend a "0" if the value is less than the 10.
Returns
Type
:String

(static) toMiddleEndian(date, divideropt, prepend0opt):String

Returns a date in middle-endian format (MM-DD-YYYY).
Parameters
date:Date
The date to check against.
divider:String = "/" (optional)
The character to use as a divider.
prepend0:Boolean = true (optional)
Whether to prepend a "0" if the value is less than the 10.
Returns
Type
:String

(static) toMinutes(sec, prepend0opt):String

Converts seconds to minutes.
Parameters
sec:Number
Seconds.
prepend0:Boolean = true (optional)
Whether to prepend a "0" if the value is less than the 10.
Returns
Type
:String

(static) tomorrow():Date

Returns tomorrow.
Returns
Type
:Date

(static) years(from, to):Array

Returns an array of years (in four digit format) from the range inputted.
Parameters
from:Number
A four digit year.
to:Number|String
A number or string. If a string is used, a range is returned with the 'from' year plus amount in the 'to' string. For example: Assuming the current year is 2012, both Datelish.years(Datelish.currYear, 2014) and Datelish.years(Datelish.currYear, "2") return [2012, 2013, 2014].
Returns
Type
:Array

(static) yesterday():Date

Returns yesterday.
Returns
Type
:Date