JodaTime Plugin
The plugin creates JODA Time objects, which makes it possible to use it from Velocity scripts in wiki pages.Installation
To use, add the com.xpn.xwiki.plugin.jodatime.JodaTimePlugin plugin definition to the xwiki.plugins property in your xwiki.cfg file (this definition is already there if you use XWiki Enterprise 1.2 Milestone 2 or above). The API is the following:/** * @see org.joda.time.DateTime#DateTime() */ public DateTime getDateTime(); /** * @see org.joda.time.DateTime#DateTime(int, int, int, int, int, int, int) */ public DateTime getDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond); /** * @see org.joda.time.DateTime#DateTime(long) */ public DateTime getDateTime(long instant); /** * @see org.joda.time.MutableDateTime#MutableDateTime() */ public MutableDateTime getMutableDateTime(); /** * @see org.joda.time.MutableDateTime#MutableDateTime(int, int, int, int, int, int, int) */ public MutableDateTime getMutableDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond); /** * @see org.joda.time.MutableDateTime#MutableDateTime(long) */ public MutableDateTime getMutableDateTime(long instant); /** * @see org.joda.time.format.DateTimeFormat#forPattern(String) */ public DateTimeFormatter getDateTimeFormatterForPattern(String pattern); /** * @see org.joda.time.format.DateTimeFormat#forStyle(String) */ public DateTimeFormatter getDateTimeFormatterForStyle(String style);
Example
## Example 1
#set($now = $xwiki.jodatime.dateTime)
#set($weekStart = $now.withDayOfWeek(1))
#set($weekEnd = $now.withDayOfWeek(7))
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForStyle('F-'))
First day of the current week is $formatter.print($weekStart)
Last day of the current week is $formatter.print($weekEnd)
## Example 2
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern("dd/MM/yyyy 'at' hh:mm"))
#set($creationDate = $xwiki.jodatime.getDateTime($doc.creationDate.time))
Document created on $formatter.print($creationDate)
## Example 3
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy.MM.dd'))
#set($myBirthday = $formatter.parseDateTime('2007.11.25'))
#set($daysLeft = $myBirthday.minus($now.millis))
$daysLeft.getDayOfYear() days left till my birthday!Result
First day of the current week is Monday, November 19, 2007 Last day of the current week is Sunday, November 25, 2007 Document created on 21/11/2007 at 02:19 4 days left till my birthday!
Version 4.1 last modified by ThomasMortagne on 10/12/2007 at 16:43
Document data
Attachments:
No attachments for this document
Comments: 0