Home

# Library goog.date.relative

Function Summary
| `format(number dateMs) ⇒ string` 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.
| `formatDay(number dateMs) ⇒ string` Accepts a timestamp in milliseconds and outputs a relative day. i.e. "Today", "Yesterday" or "Sept 15".
| `formatFullDate_((Date|goog.date.DateTime|null) date) ⇒ string` Returns a date in full date format, e.g. Tuesday, March 24, 2009.
| `formatMonth_(?Date date) ⇒ string` Returns a date in month format, e.g. Mar 15.
| `formatPast(number dateMs) ⇒ string` 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.
| `formatShortTime_((Date|goog.date.DateTime|null) date) ⇒ string` Returns a date in short-time format, e.g. 2:50 PM.

`getDateString((Date|goog.date.DateTime|null) date, string= opt_shortTimeMsg, string= opt_fullDateMsg) ⇒ string`

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.

`getDateString_((Date|goog.date.DateTime|null) date, function (number): string relativeFormatter, string= opt_shortTimeMsg, string= opt_fullDateMsg) ⇒ string`

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.

| `getMessage_(number delta, boolean future, ?goog.date.relative.Unit_ unit) ⇒ string` Gets a localized relative date string for a given delta and unit.

`getPastDateString((Date|goog.date.DateTime|null) date, string= opt_shortTimeMsg, string= opt_fullDateMsg) ⇒ string`

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.