API Docs for: 1.0.0
Show:

DateTimeUtils Class

Utility functions work working with dates and times.

Item Index

Methods

Methods

formatDate

(
  • date
)
String static

Format the date portion of a Date object.

Parameters:

  • date Mixed

    string (returned as-is), Date, milliseconds, or object specifying day,month,year

Returns:

String:

formatted date, using positions and delimiter

formatTime

(
  • time
)
String static

Format the time portion of a Date object.

Parameters:

  • time Mixed

    string (returned as-is), Date, milliseconds, or object specifying hour,minute

Returns:

String:

formatted time, using delimiter

normalize

(
  • input
  • default_time
)
Object static

Normalizes the given object by converting date_str into year,month,day, converting time_str into hour,minute (or adding in hour,minute from default_time), and adding date (instanceof Date). Individual fields take precedence over strings.

If input is a Date object, then the result contains a breakdown of the values.

Parameters:

  • input Date | Number | Object
    Can be specified either as instance of Date, a number specifying
    milliseconds since midnight Jan 1, 1970, or as an object defining
    date_str or year,month,day and (optional) either time_str or
    hour,minute.
  • default_time Object

    Default hour and minute to use if input only has date.

Returns:

Object:

normalized object defining date and time

parseDate

(
  • date
)
Object static

Inverse of formatDate(). Extracts year, month, and day from the string. The values are normalized to fall inside the default ranges.

Parameters:

  • date String

    string from DateTimeUtils.formatDate()

Returns:

Object:

year,month,day, or null

parseDate

(
  • date
  • delimiater
  • year_pos
  • month_pos
  • day_pos
)
Object static

Utility for parsing a date string that is not formatted based on the Y.DateTime configuration.

Parameters:

  • date String

    string from DateTimeUtils.formatDate()

  • delimiater String

    delimiter between the date fields

  • year_pos Number

    position of the year in the string representation: 1,2,3

  • month_pos Number

    position of the month in the string representation: 1,2,3

  • day_pos Number

    position of the day in the string representation: 1,2,3

Returns:

Object:

normalized object defining date

parseTime

(
  • time
)
Object static

Inverse of formatTime(). Extracts hour and minute from the string. Throws an error if hour is outside [0,23] or minute is outside [0,59].

Parameters:

  • time String

    string from DateTimeUtils.formatTime()

Returns:

Object:

hour,minute, or null

Properties

AM_STRING

String static

Antemeridian string.

Default: "AM"

CLOCK_DISPLAY_TYPE

Number 12 or 24 static

How hours should be displayed to the user by classes in the DateTime family: 12hr or 24hr. (Internal values are always 24hr.) This is global because your app should be consistent about how it displays times.

Default: 24

DATE_FIELD_DELIMITER

String static

Delimiter of fields in a string representation of a date.

Default: "-"

DAY_POSITION

Number static

Position of the day in a string representation of a date: 1,2,3

Default: 3

MONTH_POSITION

Number static

Position of the month in a string representation of a date: 1,2,3

Default: 2

PM_STRING

String static

Postmeridian string.

Default: "PM"

TIME_FIELD_DELIMITER

String static

Delimiter of fields in a string representation of a time.

Default: ":"

YEAR_POSITION

Number static

Position of the year in a string representation of a date: 1,2,3

Default: 1