The date namespace of Bijou.js, containing functions to format dates, do math with them and more!
Methods
# static exports.addDaysToDate(date, n) → {Date}
Adds a specified number of days to a date.
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date
|
The date to add days to |
n |
Number
|
How many days to add to the date. |
The date with the specified number of days added.
Date
# static exports.addMinutesToDate(date, n) → {Date}
Adds a certain number of minutes to a date object.
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date
|
string
|
The date to add minutes to. |
n |
Number
|
How many minutes to add to the date. |
The date with minutes added.
Date
Example
_$.addMinutesToDate(new Date(), 4);//Create a date 4 minutes from now.
# static exports.dayName(dateopt, localeopt) → {String}
Returns the name of the weekday from the Date object specified.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date
|
<optional> |
new Date() | The date object to use. |
locale |
String
|
<optional> |
en-US | The locale to use. |
The day name from the date.
String
Example
console.log(_$.dayName)); // e.g. "Friday"
# static exports.formatMilliseconds(ms) → {String}
Formats a number of milliseconds
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
Number
|
String
|
The number of milliseconds to format to a string. |
The string of formatted milliseconds.
String
Example
console.log(_$.formatMilliseconds(1324765128475)); // "1 century, 7 years, 2 days, 22 hours, 18 minutes, 48 seconds, 475 milliseconds"
# static exports.isDateValid(…val) → {Boolean}
Validates a date from a string.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
val |
any
|
<repeatable> |
The arguments of the date to validate. |
Returns if the date is valid or not.
Boolean
Example
_$.isDateValid('December 17, 1995 03:24:00'); // true
_$.isDateValid('1995-12-17T03:24:00'); // true
_$.isDateValid('1995-12-17 T03:24:00'); // false
_$.isDateValid('Duck'); // false
_$.isDateValid(1995, 11, 17); // true
_$.isDateValid(1995, 11, 17, 'Duck'); // false
_$.isDateValid({}); // false