Time

Time related utilities

Classes

Clock

Members

(inner) MONTHS :Object

Months labels

Type:
  • Object
Example
MONTHS['mx'][0] //=> "Enero"

(inner) MONTHS_SHORT :Object

Months labes in 3 chars style

Type:
  • Object
Example
MONTHS_SHORT['mx'][0] //=> "Ene"

(inner) WEEKDAYS_LONG :Object

Days of week labels

Type:
  • Object
Example
WEEKDAYS_LONG['mx'][0] //=> "Domingo"

(inner) WEEKDAYS_SHORT :Object

Days of week labels in 2 chars style

Type:
  • Object
Example
WEEKDAYS_SHORT['mx'][0] //=> "Do"

Methods

(inner) dateBasedSerial(dateopt) → {string}

Concatenates Year, Month, Day, Hour and Mins into a string to form a current time serial

Example
dateBasedSerial(new Date(2018, 1, 2, 3, 4)); //=> '201802020304'
Parameters:
Name Type Attributes Description
date Date <optional>

Date to form serial or current date by default

Returns:
Type
string

(inner) dateSpread(dateopt, paddedopt) → {Array}

Array representation of a date: [YYYY, MM, DD, HH, mm]

Example
dateSpread(new Date(2018, 1, 2, 3, 4)); //=> ['2018', '02', '02', '03', '04']
Parameters:
Name Type Attributes Default Description
date Date <optional>

Instance of Date. If not provided, date will be Date.now()

padded boolean <optional>
true

Defines if response will be padded with zeroes

Returns:
Type
Array

(inner) firstDayOfYear(dateopt) → {string}

First date of year in YYYY-MM-DD format

Example
firstDayOfYear(new Date(2018, 1, 2, 3, 4)); //=> '2018-01-01'
Parameters:
Name Type Attributes Description
date Date <optional>

Instance of Date. If not provided, date will be Date.now()

Returns:
Type
string

(inner) formatDateRange(date_gte, date_lte) → {string}

Transform a date range into a readable format

Example
formatDateRange("2018-03-01", "2018-03-31"); //=> "Mar 2018"
formatDateRange("2018-03-01", "2018-03-17"); //=> "1 - 17 Mar 2018"
formatDateRange("2018-02-23", "2018-03-17"); //=> "23 Feb - 17 Mar 2018"
formatDateRange("2017-12-20", "2018-01-10"); //=> "20 Dic - 10 Ene 2018"
Parameters:
Name Type Description
date_gte string

Lowest date of range in YYYY-MM-DD format

date_lte string

Highest date of range in YYYY-MM-DD format

Returns:
Type
string

(inner) formatDateYYYY_MM_DD(dateopt) → {string}

Formats a date into a YYYY-MM-DD string

Example
formatDateYYYY_MM_DD(new Date(2018, 1, 2, 3, 4)); //=> '2018-02-02'
Parameters:
Name Type Attributes Description
date Date <optional>

Date. If not provided, Date.now()

Returns:
Type
string

(inner) formatDayMonthYear(dateopt, localeopt) → {string}

Formats a date into a DD de MMMM YYYY readable string

Example
formatDayMonthYear(new Date(2018, 1, 2, 3, 4)); //=> '02 de Febrero 2018'
Parameters:
Name Type Attributes Default Description
date Date <optional>

Date. If not provided, Date.now()

locale string <optional>
mx

Locality string. mx by default

Returns:
Type
string

(inner) formatDayMonthYearShort(dateopt, localeopt) → {string}

Formats a date into a DD de MMM YY readable string

Example
formatDayMonthYearShort(new Date(2018, 1, 2, 3, 4)); //=> '02 Feb 18'
Parameters:
Name Type Attributes Default Description
date Date <optional>

Date. If not provided, Date.now()

locale string <optional>
mx

Locality string. mx by default

Returns:
Type
string

(inner) formatMonthYearShort(dateopt, localeopt) → {string}

Formats a date into a MMM YY readable string

Example
formatMonthYearShort(new Date(2018, 1, 2, 3, 4)); //=> 'Feb 18'
Parameters:
Name Type Attributes Default Description
date Date <optional>

Date. If not provided, Date.now()

locale string <optional>
mx

Locality string. mx by default

Returns:
Type
string

(inner) getDaysOfMonth(dateopt) → {number}

Give the count of how many days a month has. Supports leap-years

Example
getDaysOfMonth(new Date(2018, 1, 2, 3, 4)); //=> 28
Parameters:
Name Type Attributes Description
date Date <optional>

Date. If not provided, Date.now()

Returns:
Type
number

(inner) getUTCDate(date) → {Date}

Get Coordinated Universal Time

  • Why I might want to use this? new Date() adds a timezone offset. So new Date('2018','01','01'); //=> 2018-02-01T06:00:00.000Z.
  • Notice the 6 hours added in the result? That is the timezone. To avoid this, we can use UTC format. Hence, this function.
Parameters:
Name Type Description
date Date

Instance of Date

Returns:
Type
Date

(inner) isDate(date) → {boolean}

Validates that an input is instance of Date

Example
isDate(new Date()); //=> true
Parameters:
Name Type Description
date *

Element to check if is instance of Date

Returns:
Type
boolean

(inner) monthRange(dateopt) → {Object}

Generates the date_range of the month given in date

Example
monthRange(new Date('2018', '06')); //=> {from: '2018-05-01', to: '2018-05-31'}
Parameters:
Name Type Attributes Description
date Date <optional>

Instance of Date. Date.now() if not provided

Returns:
Type
Object

(inner) yesterday() → {Date}

Generates the Date of yesterday ¯\_(ツ)_/¯

Returns:
Type
Date