Methods
addDays(date, days) → {Date}
- Since:
- v1.0.0
Adds, or subtracts, the specified number of days from the provided date.
Examples
// Adds 5 days to January 1, 2019
addDays(new Date(2019, 0, 1), 5)
// -> Returns Sunday, January 6, 2019
// Counts back 5 days from January 1, 2019
addDays(new Date(2019, 0, 1), -5)
// -> Returns Thursday, December 27, 2018
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to modify. |
days |
number | The number of days to move from the provided date. A negative number will return a date before the provided date. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns a new Date instance the specified number of days from the provided date.
- Type
- Date
addMonths(date, months) → {Date}
- Since:
- v1.0.0
Adds, or subtracts, the given number of months from the provided date. In case the original date of the month doesn't occur in the result month, the day of the month will be set to the last day in the result month. IE: Add 1 month to Jan 31 will result in Feb 28.
Examples
// Add 1 month to January 5, 2019
addMonths(new Date(2019, 0, 5), 1);
// -> Returns Thursday, Thursday, February 5, 2019
// Add 1 month to January 31, 2019
addMonths(new Date(2019, 0, 31), 1);
// -> Returns Thursday, February 28, 2019 because there is no February 31.
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to add months to. |
months |
number | The number of months to move from the provided date. A negative number will return a date before the provided date. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns a new Date instance the specified number of months from the provided date.
- Type
- Date
addYears(date, days) → {Date}
- Since:
- v1.1.0
Adds, or subtracts, the specified number of years from the provided date.
Examples
// Adds 5 years to January 1, 2019
addYears(new Date(2019, 0, 1), 5)
// -> Returns Monday, January 1, 2024
// Counts back 5 days from January 1, 2019
addYears(new Date(2019, 0, 1), -5)
// -> Returns Wednesday, December 27, 2014
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to modify. |
days |
number | The number of years to move from the provided date. A negative number will return a date before the provided date. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns a new Date instance the specified number of years from the provided date.
- Type
- Date
createRange(startDate, length) → {Array.<Date>}
- Since:
- v1.0.0
Creates an array of sequential Date instances.
Examples
// Create a range with 3 dates, starting at January 1, 2019
createRange(new Date(2019, 0, 1), 3)
// -> Returns [
// Tuesday, January 1, 2019
// Wednesday, January 2, 2019
// Thursday, January 3, 2019
// ]
// Create a range with 3 dates, ending at January 1, 2019
createRange(new Date(2019, 0, 1), -3)
// -> Returns [
// Sunday, December 30, 2018
// Monday, December 31, 2018
// Tuesday, January 1, 2019
// ]
Parameters:
Name | Type | Description |
---|---|---|
startDate |
Date | number | The start date of the range. |
length |
number | The number of days to return. When it is a negative number the range will start in the past and the last day in the range will be the start date. |
Throws:
-
A TypeError is thrown when the provided values are not of type Date or Number.
- Type
- TypeError
Returns:
Returns an array with the specified number of Date instances.
- Type
- Array.<Date>
createRangeForDays(startDate, endDate) → {Array.<Date>}
- Since:
- v1.0.0
Creates an array of sequential Date instances.
Example
// Create a range with 3 dates, starting at January 1, 2019
createRangeForDays(new Date(2019, 0, 1), new Date(2019, 0, 3))
// -> Returns [
// Tuesday, January 1, 2019
// Wednesday, January 2, 2019
// Thursday, January 3, 2019
// ]
Parameters:
Name | Type | Description |
---|---|---|
startDate |
Date | number | The start date of the range (inclusive). |
endDate |
Date | number | The date when the range ends (inclusive). |
Throws:
-
-
A TypeError is thrown when the provided values are not of type Date or Number.
- Type
- TypeError
-
-
-
A RangeError is thrown when the provided end date is earlier than the start date.
- Type
- RangeError
-
Returns:
Returns an array with Date instances, starting at the start date all the way to the end date.
- Type
- Array.<Date>
createRangeForMonth(date, options) → {Array.<Date>}
- Since:
- v1.5.0
Creates an array of sequential Date instances covering an entire calendar month. By using the options it is possible to pad the month to full weeks, to always return six weeks, and to specify the first day of the week.
Examples
// Create a range for the month January 2019.
createRangeForMonth(new Date(2019, 0, 10))
// -> Returns [
// Tuesday, January 1, 2019,
// Wednesday, January 2, 2019,
// Thursday, January 3, 2019,
// ...
// Thursday, January 31, 2019
// ]
// Create a range for the month January 2019, padded to full weeks.
createRangeForMonth(new Date(2019, 0, 10), { padMonth: true })
// -> Returns [
// Monday, December 31, 2018,
// Tuesday, January 1, 2019,
// Wednesday, January 2, 2019,
// ...
// Sunday, February 3, 2019
// ]
// Create a range for the month January 2019, padded to full weeks, when a
// week starts on a Sunday.
createRangeForMonth(new Date(2019, 0, 10), { padMonth: true, firstWeekDay: 0 })
// -> Returns [
// Sunday, December 30, 2018,
// Monday, December 31, 2018,
// Tuesday, January 1, 2019,
// ...
// Saturday, February 2, 2019
// ]
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | A day in the month for which to return all the dates. |
options |
CalenderMonthRangeOptions | null | An optional parameter to shape the result of the returned range. |
Throws:
-
-
A TypeError is thrown when the provided values are not of type Date or Number.
- Type
- TypeError
-
-
-
A TypeError is thrown when the provided firstWeekDay is not of type Number.
- Type
- TypeError
-
-
-
A RangeError is thrown when the firstWeekDay is not a valid day of the week.
- Type
- RangeError
-
Returns:
Returns an array with Date instances, starting at the first day of the requested month and ending at the last day of the requested month.
- Type
- Array.<Date>
determineBoundaries(date, options) → {Boundaries}
Determines the start and end date of the range to create.
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | |
options |
CalenderMonthRangeOptions |
Returns:
- Type
- Boundaries
getDayOfYear(date) → {boolean}
- Since:
- v1.4.0
Returns which day of the year a given date is.
Example
// Which day of the year is September 27, 2019
getDayOfYear(new Date(2019, 8, 27))
// -> Returns 270
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date for which to return the day number in the year for. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns which day of the year the given date is.
- Type
- boolean
getFirstDayOfMonth(date) → {Date}
- Since:
- v1.4.0
Returns the date of the first day of the month in which the provided date falls.
Example
// Returns the first day of January 2019
getFirstDayOfMonth(new Date(2019, 0, 10, 10, 11, 12));
// -> Returns Tuesday, January 1, 2019 at 00:00:00
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date for whose month the first day should be returned. |
Throws:
-
A TypeError is thrown when the provided value is not of type Date or Number.
- Type
- TypeError
Returns:
Returns a new Date instance representing the first day of the month at midnight.
- Type
- Date
getFirstDayOfWeek(date, firstWeekDayopt) → {Date}
- Since:
- v1.0.0
Returns the first day of the week in which the provided date falls.
Examples
// Returns the first day of the week in which January 10, 2019 falls
getFirstDayOfWeek(new Date(2019, 0, 10))
// -> Returns Monday, January 7, 2019
// Returns the first day of the week in which January 10, 2019 falls for a
// locale where the week starts on Sunday (0)
getFirstDayOfWeek(new Date(2019, 0, 10), 0)
// -> Returns Sunday, January 6, 2019
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date for which to return the first day of the week. |
||
firstWeekDay |
number |
<optional> |
1
|
Optional parameter to specify on which day a week starts. By default this will be 1 (Monday). |
Throws:
-
-
A TypeError is thrown when the provided value is not of type Date or Number.
- Type
- TypeError
-
-
-
A RangeError is thrown when the firstWeekDay is not a valid day of the week.
- Type
- RangeError
-
Returns:
Returns a new Date instance with the date of the first day of the week at midnight.
- Type
- Date
getLastDayOfMonth(date) → {Date}
- Since:
- v1.0.0
Returns the date of the last day of the month in which the provided date falls.
Example
// Returns the last day of January 2019
getLastDayOfMonth(new Date(2019, 0, 10, 10, 11, 12));
// -> Returns Thursday, January 31, 2019 at 00:00:00
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date for whose month the last day should be returned. |
Throws:
-
A TypeError is thrown when the provided value is not of type Date or Number.
- Type
- TypeError
Returns:
Returns a new Date instance representing the last day of the month at midnight.
- Type
- Date
getLastDayOfWeek(date, firstWeekDayopt) → {Date}
- Since:
- v1.0.0
Returns the last day of the week in which the provided date falls.
Examples
// Returns the last day of the week in which January 10, 2019 falls
getLastDayOfWeek(new Date(2019, 0, 10))
// -> Returns Sunday, January 13, 2019
// Returns the last day of the week in which January 10, 2019 falls for a
// locale where the week starts on Sunday (0)
getLastDayOfWeek(new Date(2019, 0, 10), 0)
// -> Returns Saturday, January 12, 2019
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date for which to return the last day of the week. |
||
firstWeekDay |
number |
<optional> |
1
|
Optional parameter to specify on which day a week starts. By default this will be Monday. |
Throws:
-
-
A TypeError is thrown when the provided value is not of type Date or Number.
- Type
- TypeError
-
-
-
A RangeError is thrown when the firstWeekDay is not a valid day of the week.
- Type
- RangeError
-
Returns:
Returns a new Date instance with the date of the last day of the week at midnight.
- Type
- Date
getTimeSpan(date, otherDate, optionsopt) → {TimeSpan}
- Since:
- v1.2.0
Calculates the number of days between two dates.
Example
// Get the time span between January 1, 2019 at 00:00:00.000 and
// January 15, 2019 at 12:30:30.500
getTimeSpan(
new Date(2019, 0, 1),
new Date(2019, 0, 15, 12, 45, 30, 500)
);
// -> Returns { days: 14, hours: 12, minutes: 45, seconds: 30, milliseconds: 500 }
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
date |
Date | number | The first date. |
|
otherDate |
Date | number | The other date. |
|
options |
TimeSpanResultOptions |
<optional> |
Optional parameter to control the result of the the calculation. Only the absolute property is used. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates as a time span.
- Type
- TimeSpan
getTimeSpanInCalendarDays(date, otherDate, optionsopt) → {number}
- Since:
- v1.2.0
- See:
-
- To calculate the difference in 24 hour periods use getTimeSpanInDays.
Calculates the number of calendar days between two dates.
Example
// Get the number of calendar days between January 1 at 23:59:59.999 and
// January 2 at 00:00:00.001.
getTimeSpanInCalendarDays(
new Date(2019, 0, 1, 23, 59, 59, 999),
new Date(2019, 0, 2, 0, 0, 0, 1)
);
// -> Returns 1
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
date |
Date | number | The first date. |
|
otherDate |
Date | number | The other date. |
|
options |
TimeSpanResultOptions |
<optional> |
Optional parameter to shape the result of the the calculation. Only the absolute property is used. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in calendar days.
- Type
- number
getTimeSpanInDays(date, otherDate, optionsopt) → {number}
- Since:
- v1.2.0
- See:
-
- To calculate the difference in calendar days use getTimeSpanInCalendarDays.
Calculates the number of days, as in 24 hour periods, between two dates.
Examples
// Get the number of days between January 1 at 23:59:59.999 and
// January 2 at 00:00:00.001.
getTimeSpanInDays(
new Date(2019, 0, 1, 23, 59, 59, 999),
new Date(2019, 0, 2, 0, 0, 0, 1)
);
// -> Returns 0
// Get the number of days between January 1 at 00:00:00.000 and
// January 5 at 12:45:30.001.
getTimeSpanInDays(
new Date(2019, 0, 1),
new Date(2019, 0, 5, 12, 45, 30, 1)
);
// -> Returns 4
// Get the number of days and fraction of days between January 1
// at 00:00:00.000 and January 2 at 12:00:00.000.
getTimeSpanInDays(
new Date(2019, 0, 1),
new Date(2019, 0, 2, 12),
{ rounded: false }
);
// -> Returns 1.5
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
date |
Date | number | The first date. |
|
otherDate |
Date | number | The other date. |
|
options |
TimeSpanResultOptions |
<optional> |
Optional parameter to shape the result of the the calculation. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in days.
- Type
- number
getTimeSpanInHours(date, otherDate, options) → {number}
- Since:
- v1.2.0
Calculates the number of hours between two dates.
Examples
// Calculate the number of hours between January 1, 2019 at 01:00:00.000
// and January 1, 2019 at 02:30:00.000
getTimeSpanInHours(
new Date(2019, 0, 1, 1, 0),
new Date(2019, 0, 1, 2, 30)
);
// -> Returns 1
// Calculate the number of hours and fractions of an hour between
// January 1, 2019 at 01:00:00.000 and January 1, 2019 at 02:30:00.000
getTimeSpanInHours(
new Date(2019, 0, 1, 1, 0),
new Date(2019, 0, 1, 2, 30),
{ rounded: false }
);
// -> Returns 1.5
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The first date. |
otherDate |
Date | number | The other date |
options |
TimeSpanResultOptions | Optional parameter to shape the result of the the calculation. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in hours.
- Type
- number
getTimeSpanInMilliseconds(date, otherDate, optionsopt) → {number}
- Since:
- v1.2.0
Calculates the number of milliseconds between two dates.
Examples
// Get the milliseconds between January 1 at 0:0:1.000
// and January 1 at 0:0:2.500.
getTimeSpanInMilliseconds(
new Date(2019, 0, 1, 0, 0, 1),
new Date(2019, 0, 1, 0, 0, 2, 500)
);
// -> Returns 1500
// Get the milliseconds between January 1 at 0:0:1.000
// and January 1 at 0:0:2.500 in the order the dates
// are provided.
getTimeSpanInMilliseconds(
new Date(2019, 0, 1, 0, 0, 1),
new Date(2019, 0, 1, 0, 0, 2, 500),
{ absolute: false }
);
// -> Returns -1500
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
date |
Date | number | The first date. |
|
otherDate |
Date | number | The other date. |
|
options |
TimeSpanResultOptions |
<optional> |
Optional parameter to control the result of the the calculation. Only the absolute property is used. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in milliseconds.
- Type
- number
getTimeSpanInMinutes(date, otherDate, options) → {number}
- Since:
- v1.2.0
Calculates the number of minutes between two dates.
Examples
// Calculate the number of minutes between January 1, 2019 at 00:01:00.000
// and January 1, 2019 at 00:02:30.500
getTimeSpanInMinutes(
new Date(2019, 0, 1, 0, 1),
new Date(2019, 0, 1, 0, 2, 30, 500)
);
// -> Returns 1
// Calculate the number of minutes and fractions of a minute between
// January 1, 2019 at 00:01:00.000 and January 1, 2019 at 00:02:30.500
getTimeSpanInMinutes(
new Date(2019, 0, 1, 0, 1),
new Date(2019, 0, 1, 0, 2, 30, 500),
{ rounded: false }
);
// -> Returns 1.5083333333333333
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The first date. |
otherDate |
Date | number | The other date |
options |
TimeSpanResultOptions | Optional parameter to shape the result of the the calculation. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in minutes.
- Type
- number
getTimeSpanInSeconds(date, otherDate, options) → {number}
- Since:
- v1.2.0
Calculates the number of seconds between two dates.
Examples
// Calculate the number of seconds between January 1, 2019 at 00:01:00.000
// and January 1, 2019 at 00:02:30.500
getTimeSpanInSeconds(
new Date(2019, 0, 1, 0, 1),
new Date(2019, 0, 1, 0, 2, 30, 500)
);
// -> Returns 90
// Calculate the number of seconds and fractions of a second between
// January 1, 2019 at 00:01:00.000 and January 1, 2019 at 00:02:30.500
getTimeSpanInSeconds(
new Date(2019, 0, 1, 0, 1),
new Date(2019, 0, 1, 0, 2, 30, 500),
{ rounded: false }
);
// -> Returns 90.5
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The first date. |
otherDate |
Date | number | The other date |
options |
TimeSpanResultOptions | Optional parameter to shape the result of the the calculation. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns the difference between two dates in seconds.
- Type
- number
isEarlier(date, maxDate, isInclusiveopt) → {boolean}
- Since:
- v1.0.0
Test if the provided date falls before a maximum date. The comparison is made including the time component of the date.
Examples
// Tests if January 2018 is earlier than January 2019
isEarlier(new Date(2018, 0, 1), new Date(2019, 0, 1));
// -> Returns true, January 2018 is earlier.
// Tests if date is earlier to itself, by default this is true
isEarlier(new Date(2019, 0, 1), new Date(2019, 0, 1));
// -> Returns true, January 2019 is earlier/equal to itself.
// Tests if date is earlier to itself but exclude the max date itself.
isEarlier(new Date(2019, 0, 1), new Date(2019, 0, 1), false);
// -> Returns false, January 2019 is not earlier than itself.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date to check against a maximum date. |
||
maxDate |
Date | number | The maximum date to compare against. |
||
isInclusive |
boolean |
<optional> |
true
|
Optional parameter to specify whether the max date is considered a valid date. By default this is true, the max date itself is considered to be valid. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date is earlier than the provided max date.
- Type
- boolean
isInRange(date, minDate, maxDate, isMinMaxInclusiveopt) → {boolean}
- Since:
- v1.0.0
Tests if a date is between two other dates.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date to check if it falls within the specified range of dates. |
||
minDate |
Date | number | The minimum date to compare against. |
||
maxDate |
Date | number | The maximum date to compare against. |
||
isMinMaxInclusive |
boolean |
<optional> |
true
|
Optional parameter to specify whether the min and max dates are considered a valid date. By default this is true, the min and max date itself are considered to be valid. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date is after the min date and before the max date.
- Type
- boolean
isLater(date, minDate, isInclusiveopt) → {boolean}
- Since:
- v1.0.0
Test if the provided date falls after a minimum date.
Examples
// Tests if January 2019 is later than January 2018
isLater(new Date(2018, 0, 1), new Date(2019, 0, 1));
// -> Returns true, January 2019 is later.
// Tests if date is later to itself, by default this is true
isLater(new Date(2019, 0, 1), new Date(2019, 0, 1));
// -> Returns true, January 2019 is later/equal to itself.
// Tests if date is later to itself but exclude the min date itself.
isLater(new Date(2019, 0, 1), new Date(2019, 0, 1), false);
// -> Returns false, January 2019 is not later than itself.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date to check against a minimum date. |
||
minDate |
Date | number | The minimum date to compare against. |
||
isInclusive |
boolean |
<optional> |
true
|
Optional parameter to specify whether the min date is considered a valid date. By default this is true, the min date itself is considered to be valid. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date is later than the provided min date.
- Type
- boolean
isLeapYear(date) → {boolean}
- Since:
- v1.3.0
Tests if the provided date falls in a leap year.
Example
// Is a date in the year 2000 in a leap year?
isLeapYear(new Date(2000, 6, 20))
// -> Returns true
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to test. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date falls in a leap year.
- Type
- boolean
isSameMonthAndYear(date, otherDate) → {boolean}
- Since:
- v1.1.0
Checks if two dates fall in the same month of the same year
Examples
// Check if January 1, 2019 and January 20, 2019 fall in the same month
isSameMonthAndYear(new Date(2019, 0, 1), new Date(2019, 0, 20))
// -> Returns true
// Check if January 1 in 2019 and 2020 fall in the same month
isSameMonthAndYear(new Date(2019, 0, 1), new Date(2020, 0, 1))
// -> Returns false
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to check |
otherDate |
Date | number | The other date to check |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when both dates fall in the same month of the same year.
- Type
- boolean
isToday(date) → {boolean}
- Since:
- v1.0.0
Checks if the provided date is for the current date. It only checks if the date related properties match with today. Time related properties, like hours and minutes, are ignored.
Example
// Tests if a date instance is for today
isToday(new Date())
// -> Returns true, by default a new Date instance is for today.
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date to check to see if it is today. |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date is today.
- Type
- boolean
isValidDate(value) → {boolean}
- Since:
- v1.0.0
Checks if the provided value is an instance of Date representing a valid date.
Examples
// For a Date instance with a valid date
isValidDate(new Date())
// -> Returns true
// For a Date instance with a invalid date
isValidDate(new Date('foo'))
// -> Returns false
// For a valid timestamp
isValidDate(1563362089032)
// -> Returns false, while a valid timestamp it is not an instance of Date.
Parameters:
Name | Type | Description |
---|---|---|
value |
any | The value to check. |
Returns:
Returns true when the provided value is a Date instance with a valid date.
- Type
- boolean
isWeekend(date, weekendDaysopt) → {boolean}
- Since:
- v1.0.0
Tests if the provided date falls on the weekend.
Examples
// Checks if Friday, January 4, 2019 falls on the weekend.
isWeekend(new Date(2019, 0, 4))
// -> Returns false as by default the weekend is Saturday and Sunday.
// Checks if Friday, January 4, 2019 is part of the weekend for a locale
// where the weekend falls on Friday and Saturday.
isWeekend(new Date(2019, 0, 4), [5, 6])
// -> Returns true
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
date |
Date | number | The date to test |
||
weekendDays |
Array.<number> |
<optional> |
[0,6]
|
Optional parameter to specify the days of the week which make up the weekend. By default this will be [0, 6] (Saturday and Sunday). |
Throws:
-
A TypeError is thrown when the arguments are not of the expected type.
- Type
- TypeError
Returns:
Returns true when the provided date falls on the weekend.
- Type
- boolean
removeTime(date) → {Date}
- Since:
- v1.0.0
Returns a new Date instance containing only the year, month, and day of the provided date. All time related properties are set to 0.
Example
// Returns a date instance with the time set to midnight for Tuesday,
// January 1, 2019 at 10:11:12.13
removeTime(new Date(2019, 0, 1, 10, 11, 12, 13))
// -> Returns January 1, 2019 at 00:00:00.000
Parameters:
Name | Type | Description |
---|---|---|
date |
Date | number | The date from which to strip the time. |
Throws:
-
A TypeError is thrown when the provided value is not of type Date or Number.
- Type
- TypeError
Returns:
A new Date instance with only the year, month, and date from the provided date.
- Type
- Date
Type Definitions
Boundaries
Properties:
Name | Type | Description |
---|---|---|
start |
Date | The first day of the range. |
end |
Date | The last day of the range. |
Type:
- Object
CalenderMonthRangeOptions
- Since:
- v1.5.0
Properties:
Name | Type | Description |
---|---|---|
firstWeekDay |
number | Specify on which day a week starts. By default this will be 1 (Monday). |
padMonth |
boolean | Indicated whether or not the month should be padded to full weeks. This is false by default. |
padWeeks |
boolean | Indicates whether or not a padded month should always be 6 weeks long. This setting is only used when padMonth is true and defaults to false. |
Options to control the output of a calendar month range.
Type:
- Object
TimeSpan
- Since:
- v1.2.0
Properties:
Name | Type | Description |
---|---|---|
days |
number | The number of days passed between two dates. Please note that these are not calendar days but periods of 24 hours. |
hours |
number | The number of hours that don't make a full day. |
minutes |
number | The number of minutes that don't make a full hour. |
seconds |
number | The number of seconds that don't make a full minute. |
milliseconds |
number | The number of milliseconds that don't make a full second. |
Represents a time interval.
Type:
- Object
TimeSpanResultOptions
- Since:
- v1.2.0
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
absolute |
boolean |
<optional> |
true
|
Indicates whether or not the result should be calculated between the latest and earliest date. By default this is true. When false the result can be a negative number in case the first date is earlier than the second date. |
rounded |
boolean |
<optional> |
true
|
Returns the result as an integer rounded to the nearest completed unit of time. |
Options to control the output of a time span calculation.
Type:
- Object