Date Script Service
Last modified by Admin on 2024/12/11 00:49
Script services to display dates in a nice way. |
Type | JAR |
Category | API |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Compatibility | Since XWiki 10.5-rc-1 and XWiki 9.11.5. |
Description
This script services offer some methods to display dates in a pretty way, and supporting a lot of locales (contrary to $datetool). It is currently based on PrettyTime.
Examples
Here are some Velocity examples:
## Example 1:
$services.date.displayTimeAgo($datetool.date())
## Displays: moments from now ("à l'instant" in French)
## Example 2:
$services.date.displayTimeAgo($xwiki.jodatime.dateTime.minusMinutes(12).toDate())
## Displays: 12 minutes ago ("il y a 12 minutes" in French)
## Example3: You can also specify the locale you want
$services.date.displayTimeAgo($xwiki.jodatime.dateTime.minusHours(1).toDate(), "es")
## Displays "hace 1 hora"
$services.date.displayTimeAgo($datetool.date())
## Displays: moments from now ("à l'instant" in French)
## Example 2:
$services.date.displayTimeAgo($xwiki.jodatime.dateTime.minusMinutes(12).toDate())
## Displays: 12 minutes ago ("il y a 12 minutes" in French)
## Example3: You can also specify the locale you want
$services.date.displayTimeAgo($xwiki.jodatime.dateTime.minusHours(1).toDate(), "es")
## Displays "hace 1 hora"
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).
You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.
Dependencies
Dependencies for this extension (org.xwiki.platform:xwiki-platform-date 16.10.1):
- org.xwiki.commons:xwiki-commons-component-api 16.10.1
- org.xwiki.commons:xwiki-commons-script 16.10.1
- org.xwiki.platform:xwiki-platform-localization-api 16.10.1
- org.ocpsoft.prettytime:prettytime 5.0.9.Final