DateUtils

DateUtils ⇐ Class

Deprecated

Kind: global class
Extends: Class

DateUtils()

This static class represents DateUtils. It provides several tools to work with Dates

DAYS_IN_WEEK

number of days in one week

Kind: static property of DateUtils

DAYS_IN_YEAR

number of days in one year (omitting leap years)

Kind: static property of DateUtils

MONTH_IN_YEAR

number of months in one year

Kind: static property of DateUtils

ONE_SECOND : number

Value for one second in millisecond.

Kind: static constant of DateUtils

ONE_MINUTE : number

Value for one minute in millisecond.

Kind: static constant of DateUtils

ONE_HOUR : number

value for one hour in millisecond.

Kind: static constant of DateUtils

ONE_DAY : number

value for one day in millisecond.

Kind: static constant of DateUtils

ONE_WEEK : number

value for one week day in millisecond.

Kind: static constant of DateUtils

FORMAT_TOKEN : RegExp

Regex for format replacement

Kind: static constant of DateUtils

TIMEZONE_REGEX : RegExp

Regex for timezone replacement

Kind: static constant of DateUtils

TIMEZONE_CLIP_REGEX : RegExp

Regex for timezone clip replacement

Kind: static constant of DateUtils

compare(firstDate, secondDate) ⇒ number

Compare the first date against second date.

Kind: static method of DateUtils
Returns: number - -1 : if firstDate < secondDate 0 : if firstDate === secondDate 1 : if firstDate > secondDate NaN : if firstDate or secondDate is an illegal date

ParamTypeDescription
firstDateDate

the first date

secondDateDate

the second date

isBefore(firstDate, secondDate) ⇒ boolean

Check if the secondDate date is before the firstDate

Kind: static method of DateUtils

ParamTypeDescription
firstDateDate

Date to compare

secondDateDate

Date to compare

isAfter(firstDate, secondDate) ⇒ boolean

Check if the secondDate date is after the firstDate

Kind: static method of DateUtils

ParamTypeDescription
firstDateDate

Date to compare

secondDateDate

Date to compare

isBetween(date, start, end) ⇒ boolean

Check if the date is between the start and end dates.

Kind: static method of DateUtils
Warning: Returns false if start date is after end date

ParamType
dateDate
startDate
endDate

diff(firstDate, secondDate, [diffYear]) ⇒ Object

Gap between two date.

Kind: static method of DateUtils
Returns: Object - Like: {sec: {number}, min: {number}, hour: {number}, day: {number}, year: {}}

ParamTypeDescription
firstDateDate

Date to compare

secondDateDate

Date to compare

[diffYear]Boolean

If true, year will be counted. (false by default) - Based of 365 days

relativeTimeByNow(date) ⇒ number

Return a number that tell how many milliseconds is passed from now since the date, or how many milliseconds it remains to reach the date from now.

Kind: static method of DateUtils

ParamType
dateDate

addMilliseconds(date, value)

Add or subtract milliseconds to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of milliseconds to add. Could be negative to subtract some.

addSeconds(date, value)

Add or subtract seconds to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of seconds to add. Could be negative to subtract some.

addMinutes(date, value)

Add or subtract minutes to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of minutes to add. Could be negative to subtract some.

addHours(date, value)

Add or subtract hours to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of hours to add. Could be negative to subtract some.

addDays(date, value)

Add or subtract days to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of days to add. Could be negative to subtract some.

addWeeks(date, value)

Add or subtract weeks to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of weeks to add. Could be negative to subtract some.

addMonths(date, value)

Add or subtract months to date.

Kind: static method of DateUtils
Warning: this implementation remove days if the new month doesn’t have the matching day number (30/31 => 28/29/30)

ParamTypeDescription
dateDate
valuenumber

the number of months to add. Could be negative to subtract some.

addYears(date, value)

Add or subtract years to date.

Kind: static method of DateUtils

ParamTypeDescription
dateDate
valuenumber

the number of years to add. Could be negative to subtract some.

removeDays(date, days)

Use addDays function with a negative parameter instead of that function.

Subtraction of a duration in days

Kind: static method of DateUtils

ParamTypeDescription
dateDate
daysnumber

duration in days

removeHours(date, hours)

Use addHours function with a negative parameter instead of that function.

Subtraction of a duration in hours

Kind: static method of DateUtils

ParamTypeDescription
dateDate
hoursnumber

duration in hours

removeMinutes(date, minutes)

Use addMinutes function with a negative parameter instead of that function.

Subtraction of a duration in minutes

Kind: static method of DateUtils

ParamTypeDescription
dateDate
minutesnumber

duration in minutes

add(date, config)

Add or subtract several components of a datetime

Kind: static method of DateUtils

ParamType
dateDate
configObject
config.millisecondsnumber
config.secondsnumber
config.minutesnumber
config.hoursnumber
config.daysnumber
config.weeksnumber
config.monthsnumber
config.yearsnumber

isLeapYear(year) ⇒ boolean

Is year in param a leap one.

Kind: static method of DateUtils
See

  • https://en.wikipedia.org/wiki/Leap_year#Algorithm
  • http://www.ecma-international.org/ecma-262/6.0/#sec-year-number
ParamType
yearDate | number

getDayOfYear(date) ⇒ number

Return the number of day since the start of the date year.

Kind: static method of DateUtils

ParamType
dateDate

getWeekOfYear(target, [weekstart]) ⇒ number

Return the date week number.

Kind: static method of DateUtils
See

  • https://en.wikipedia.org/wiki/Week#Week_numbering
  • https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
ParamTypeDescription
targetDate
[weekstart]number

(0: sunday, 1: Monday,...). Monday by default (as ISO standard)

getDaysInMonth([month], [year]) ⇒ number

Get the number of days in given month of given year.

Kind: static method of DateUtils

ParamTypeDescription
[month]number

0-based month number. Current mont of current year if not specified

[year]number

current year if not specified

isSameDay(firstDate, secondDate) ⇒ boolean

Are firstDate and secondDate the same day?

Kind: static method of DateUtils

ParamType
firstDateDate
secondDateDate

isNextDay(firstDate, secondDate) ⇒ boolean

Is secondDate the next day after firstDate?

Kind: static method of DateUtils

ParamType
firstDateDate
secondDateDate

isPreviousDay(firstDate, secondDate) ⇒ boolean

Is secondDate the next day before firstDate?

Kind: static method of DateUtils

ParamType
firstDateDate
secondDateDate

isToday(date) ⇒ boolean

Is current date today ?

Kind: static method of DateUtils

ParamType
dateDate

isYesterday(date) ⇒ boolean

Is given date yesterday ?

Kind: static method of DateUtils

ParamType
dateDate

isTomorrow(date) ⇒ boolean

Is given date Tomorrow ?

Kind: static method of DateUtils

ParamType
dateDate

moveToDayOfWeek(date, day, [orient])

Move given date to next or last occurrence of given day of week

Kind: static method of DateUtils

ParamTypeDescription
dateDate
daynumber

Wanted day (0: sunday, 1: monday, 2: tuesday,...)

[orient]number

If 1, get next occurrence of the day, else if -1 get previous occurrence of the day. Default value : 1.

today() ⇒ Date

Returns a Date object corresponding to today at 00:00:00

Kind: static method of DateUtils

tomorrow() ⇒ Date

Returns a Date object corresponding to tomorrow at 00:00:00

Kind: static method of DateUtils

yesterday() ⇒ Date

Returns a Date object corresponding to yesterday at 00:00:00

Kind: static method of DateUtils

now() ⇒ Date

Return the current Date.

Kind: static method of DateUtils

clone(date) ⇒ Date

Clone the Date.

Kind: static method of DateUtils
Returns: Date - Cloned date

ParamType
dateDate

clearTime(date)

Reset hours minutes seconds and milliseconds to 0.

Kind: static method of DateUtils

ParamType
dateDate

floor30(date)

Round at the lowest half hour

Kind: static method of DateUtils

ParamType
dateDate

floor15(date)

Round at the lowest quarter hour.

Kind: static method of DateUtils

ParamType
dateDate

formatTime(time, mask) ⇒ string

Format a number corresponding to a time in millisecond to a readable format following some ISO 8601

Kind: static method of DateUtils

ParamTypeDescription
timenumber

time in milliseconds

maskstring

Define the way the string will be formatted

Example (Mask options)

H    Hours; no leading zero for single-digit hours
HH    Hours; leading zero for single-digit hours
M    Minutes; no leading zero for single-digit minutes.
MM    Minutes; leading zero for single-digit minutes.
s    Seconds; no leading zero for single-digit seconds.
ss    Seconds; leading zero for single-digit seconds.
l    Milliseconds; gives 3 digits.
L    Milliseconds; gives 2 digits.
'...', "..."    Literal character sequence. Surrounding quotes are removed.

formatDate(date, mask, utc) ⇒ string

Format a date based on some ISO 8601

Kind: static method of DateUtils

ParamTypeDescription
dateDate

The date to format

maskstring

Define the way the string will be formatted

utcboolean

if true, convert local time to UTC

Example (Mask options)

d    Day of the month as digits; no leading zero for single-digit days.
dd    Day of the month as digits; leading zero for single-digit days.
m    Month as digits; no leading zero for single-digit months.
mm    Month as digits; leading zero for single-digit months.
yy    Year as last two digits; leading zero for years less than 10.
yyyy    Year represented by four digits.
h    Hours; no leading zero for single-digit hours (12-hour clock).
hh    Hours; leading zero for single-digit hours (12-hour clock).
H    Hours; no leading zero for single-digit hours (24-hour clock).
HH    Hours; leading zero for single-digit hours (24-hour clock).
M    Minutes; no leading zero for single-digit minutes.
MM    Minutes; leading zero for single-digit minutes.
o    GMT/UTC timezone offset, e.g. -0500 or +0230.
s    Seconds; no leading zero for single-digit seconds.
ss    Seconds; leading zero for single-digit seconds.
l    Milliseconds; gives 3 digits.
L    Milliseconds; gives 2 digits.
t    Lowercase, single-character time marker string: a or p.
tt    Lowercase, two-character time marker string: am or pm.
T    Uppercase, single-character time marker string: A or P.
TT    Uppercase, two-character time marker string: AM or PM.
Z    US timezone abbreviation, e.g. EST or MDT. For non-US timezones, the GMT/UTC offset is returned, e.g. GMT-0500
'...', "..."    Literal character sequence. Surrounding quotes are removed.
UTC:    Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.