The goog.date.relative Namespace

.format(dateMs)

Accepts a timestamp in milliseconds and outputs a relative time in the form of "1 hour ago", "1 day ago", "in 1 hour", "in 2 days" etc. If the date delta is over 2 weeks, then the output string will be empty.

dateMs {number}
Date in milliseconds.
returns {string}
The formatted date.

.formatDay(dateMs)

Accepts a timestamp in milliseconds and outputs a relative day. i.e. "Today", "Yesterday" or "Sept 15".

dateMs {number}
Date in milliseconds.
returns {string}
The formatted date.

.formatPast(dateMs)

Accepts a timestamp in milliseconds and outputs a relative time in the form of "1 hour ago", "1 day ago". All future times will be returned as 0 minutes ago. This is provided for compatibility with users of the previous incarnation of the above {@see #format} method who relied on it protecting against future dates.

dateMs {number}
Date in milliseconds.
returns {string}
The formatted date.

.getDateString(date, opt_shortTimeMsg, opt_fullDateMsg)

Formats a date, adding the relative date in parenthesis. If the date is less than 24 hours then the time will be printed, otherwise the full-date will be used. Examples: 2:20 PM (1 minute ago) Monday, February 27, 2009 (4 days ago) Tuesday, March 20, 2005 // Too long ago for a relative date.

date {Date|goog.date.DateTime}
A date object.
opt_shortTimeMsg {string=}
An optional short time message can be provided if available, so that it's not recalculated in this function.
opt_fullDateMsg {string=}
An optional date message can be provided if available, so that it's not recalculated in this function.
returns {string}
The date string in the above form.

.getPastDateString(date, opt_shortTimeMsg, opt_fullDateMsg)

Formats a date, adding the relative date in parenthesis. Functions the same as #getDateString but ensures that the date is always seen to be in the past. If the date is in the future, it will be shown as 0 minutes ago. This is provided for compatibility with users of the previous incarnation of the above {@see #getDateString} method who relied on it protecting against future dates.

date {Date|goog.date.DateTime}
A date object.
opt_shortTimeMsg {string=}
An optional short time message can be provided if available, so that it's not recalculated in this function.
opt_fullDateMsg {string=}
An optional date message can be provided if available, so that it's not recalculated in this function.
returns {string}
The date string in the above form.