DateTime

DateTime

Right Track Date Time

This class handles the various representations of dates and times used by the GTFS Spec and the Right Track Library and the various transformations between them.

Time Formats

  • string hh:mm aa (1:30 PM) | Human Readable Time
  • string HH:mm:ss (13:30:00) | GTFS Time
  • string HH:mm (13:30)
  • string HHmm (1330)
  • int seconds since midnight (7:00 am = 25200) | Time Seconds

Date Formats

  • int yyyymmdd (20170930) | Date Integer

Module: utils/DateTime

Constructor

new DateTime(time, date)

Source:

Right Track Date Time Constructor

Parameters:
Name Type Description
time string | int

String or Integer representation of the time. Can be in one of the following formats: 1) HH:mm:ss 2) HH:mm 3) HHmm 4) h:mm aa or 5) an integer of the number of seconds since midnight (ex 7:00 am = 25200)

date int

The date of the DateTime in the format yyyymmdd

Methods

(static) create(time, date) → {DateTime}

Source:

DateTime Factory: with time and date

Parameters:
Name Type Description
time string | int

Time

date int

Date

Returns:

DateTime

Type
DateTime

(static) createFromDate(date) → {DateTime}

Source:

DateTime Factory: with date

Parameters:
Name Type Description
date int

Date

Returns:

DateTime

Type
DateTime

(static) createFromJSDate(jd)

Source:

DateTime Factory: with JavaScript Date

Parameters:
Name Type Description
jd Date

JavaScript Date

(static) createFromTime(time, guessDateopt) → {DateTime}

Source:

DateTime Factory: with time

Parameters:
Name Type Attributes Default Description
time string

Time

guessDate boolean <optional>
false

Set to true to guess the Date relative to today

Returns:

DateTime

Type
DateTime

(static) now() → {DateTime}

Source:

DateTime Factory: date and time of now

Returns:

DateTime

Type
DateTime

clone() → {DateTime}

Source:

Create a new DateTime Object with the properties of this one

Returns:

DateTime with same date and time

Type
DateTime

deltaDays(delta) → {DateTime}

Source:

Add or Subtract the specified number of days to the DateTime's date

Parameters:
Name Type Description
delta

+/- number of days to add

Returns:

return the DateTime

Type
DateTime

deltaMins(delta) → {DateTime}

Source:

Add or Subtract the specified number of minutes to the DateTime's time

Parameters:
Name Type Description
delta

+/- number of minutes to add

Returns:

return the DateTime

Type
DateTime

getDateDOW() → {string}

Source:

Get the full name of the weekday of the date (monday, tuesday, etc)

Returns:

day of week

Type
string

getDateInt() → {int}

Source:

Get the integer representation of the date (yyyymmdd)

Returns:

date integer (yyyymmdd)

Type
int

getDateReadable(dow) → {string}

Source:

Get the human readable date ([Thu, ]Apr 18, 2019)

Parameters:
Name Type Description
dow boolean

When true, include the day of the week

Returns:

human readable date

Type
string

getTimeGTFS() → {string}

Source:

Get the GTFS Spec time representation (HH:mm:ss)

Returns:

GTFS Time (HH:mm:ss)

Type
string

getTimeInt() → {string}

Source:

Get the Time in HHmm format

Returns:

HHmm

Type
string

getTimeReadable() → {string}

Source:

Get the human readable time (12 hr with AM/PM)

Returns:

human readable time

Type
string

getTimeSeconds() → {int}

Source:

Get the time in seconds since midnight

Returns:

time integer in seconds

Type
int

isDateSet() → {boolean}

Source:

Check if the date is set

Returns:

true if the date is set

Type
boolean

toHTTPString() → {string}

Source:

Get a String representation of the DateTime to be used in HTTP Headers

Returns:

HTTP Header String

Type
string

toMySQLString() → {string}

Source:

Get a String representation of the DateTime to be used as a MySQL DateTime

Returns:

MySQL DateTime String

Type
string

toString() → {string}

Source:

Get a String representation of the DateTIme

Returns:

string of DateTime

Type
string

toTimestamp() → {number}

Source:

Get a timestamp (in ms) of the DateTime

Returns:

timestamp (ms) of DateTime

Type
number