Type | Plugin |
Category | |
Developed by | Unknown |
Rating | |
License | Unknown |
Table of contents
Description
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);
* @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!
#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!
Parsing date-time from string and comparing with current date-time
{{velocity}}
#set($strDateTime = "2010-03-12 14:16:31.0")
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd HH:mm:ss.S"))
#set($timestamp = $formatter.parseMillis($strDateTime))
#set($datetime = $formatter.parseDateTime($strDateTime))
#if($timestamp == $datetime.millis)
This should always be true!
#end
#set($now = $util.date.time)
#if($timestamp < $now)
In the past!
#elseif($timestamp == $now)
Present!
#else
In the future!
#end
{{/velocity}}
#set($strDateTime = "2010-03-12 14:16:31.0")
#set($formatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd HH:mm:ss.S"))
#set($timestamp = $formatter.parseMillis($strDateTime))
#set($datetime = $formatter.parseDateTime($strDateTime))
#if($timestamp == $datetime.millis)
This should always be true!
#end
#set($now = $util.date.time)
#if($timestamp < $now)
In the past!
#elseif($timestamp == $now)
Present!
#else
In the future!
#end
{{/velocity}}
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!