EasyDate is a jQuery plugin to format dates into a human-readable form and continuously update them to stay accurate while the user remains on the page. The plugin will parse a RFC 1123 valid timestamp from a DOM element's title attribute or innerHTML property and format it into a human-readable form (e.g., "2 weeks ago").
EasyDate is currently undergoing initial releases and should not be considered stable for production use but is encouraged to be used for development. A stable release should be expected in the coming weeks. Please report any problems or feature requests via email.
<abbr title="Fri, 24 May 2013 04:01:50 -0700" class="easydate"></abbr>
<abbr class="easydate">Fri, 24 May 2013 01:01:50 -0700</abbr>
JavaScript:
jQuery(function($) {
$(".easydate").easydate([options]);
});
Note: the abbr element is not
supported by IE6. Use a span or another element
to support IE6.
The easydate method takes one optional
argument: an options object. The following properties can be
defined. All properties are optional.
| Property | Type | Description |
|---|---|---|
live |
Boolean |
Determines if EasyDate should continuously keep dates
updated. If set to false, dates will be static. Default: true
|
set_title |
Boolean |
Determines if EasyDate should set the title attribute
of the DOM element to the original RFC 1123 timestamp if
the title attribute is empty. Default: true
|
format_future |
Boolean |
Determines if EasyDate should format dates that are in
the future. Default: true
|
format_past |
Boolean |
Determines if EasyDate should format dates that are in
the past. Default: true
|
units |
Array |
This property is an array of unit objects. The array
must be sorted in order of ascending unit limits. The
unit object has the following properties:
|
uneasy_format |
Function |
A function that is used to format the date if the date
does not fall within any units' limits. For example, if
the maximum unit is "hour" with a limit of 86400 seconds
(one day), then this function will be used to format
the date once it is more than one day in the future or
past. The function is passed a date object as the only
argument.
|
locale |
Object |
An object containing key/value pairs for all localization strings needed by EasyDate. In addition to "in" and "ago", all unit names (in both singular and plural forms) should be defined. Two special keys exist for string formatting
(
The following predefined locales are available.
|
The following functions are not required to make use of EasyDate but are provided in case the functionality is needed.
$.easydate.pause( [selector] )$.easydate.resume( [selector] )$.easydate.set_now( date )$.easydate.get_now( )$.easydate.format_date( date [, options] )