|
Jive Forums API (5.5.20.2-oracle) Developer Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jivesoftware.base.action.util.DateUtils
public class DateUtils
A formatter for dates - uses a fast internal date formatter. Use this class when formatting dates in skins - it will honor user preferences for locales.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_DATE_PATTERN
|
static java.lang.String |
DEFAULT_SHORT_DATE_PATTERN
|
static long |
ONE_DAY_IN_MILLIS
|
Constructor Summary | |
---|---|
DateUtils(javax.servlet.http.HttpServletRequest request,
User user)
|
Method Summary | |
---|---|
protected static java.lang.String |
convertDateString(java.lang.String dateString,
java.lang.String fromPattern,
java.lang.String toPattern)
Helper method to convert a date string from one pattern to another |
static boolean |
equalsIgnoreTimestamp(java.util.Date first,
java.util.Date second)
Determines whether the dates are both on the same day |
static java.util.Calendar |
findMidnight(java.util.Calendar input)
|
static long |
findMidnight(java.util.Date input)
Helper method to return the input date at midnight. |
java.lang.String |
formatDate(java.util.Date date)
Returns a date formatted using the page user's locale and timezone for correct date formatting of the passed in date. |
static java.lang.String |
formatDate(java.util.Date date,
java.util.Locale locale)
Formats a date in the DateFormat pattern for the specified Locale |
static java.lang.String |
genericizeDateString(java.lang.String dateString,
java.util.Locale locale)
Converts a localized date string to a generic date string (MM/dd/yyyy) |
FastDateFormat |
getDateFormat()
Returns a date formatter using the page user's locale and timezone for correct date formatting. |
static java.lang.String |
getDatePattern()
Returns the date pattern used in all fields where the user can input text. |
static java.util.Date |
getMaxDate()
Returns the maximum date value allowed. |
FastDateFormat |
getMediumDateFormat()
Returns a medium date formatter using the page user's locale and timezone for correct date formatting. |
java.lang.String |
getMediumFormatDate()
Returns a medium date formatted using the page user's locale and timezone for correct date formatting of the current date and time. |
java.lang.String |
getMediumFormatDate(java.util.Date date)
Returns a short date formatted using the page user's locale and timezone for correct date formatting of the passed in date. |
FastDateFormat |
getMediumTimeFormat()
Returns a medium date formatter using the page user's locale and timezone for correct time formatting. |
FastDateFormat |
getShortDateFormat()
Returns a short date formatter using the page user's locale and timezone for correct date formatting. |
java.lang.String |
getShortFormatDate()
Returns a short date formatted using the page user's locale and timezone for correct date formatting of the current date and time. |
java.lang.String |
getShortFormatDate(java.util.Date date)
Returns a short date formatted using the page user's locale and timezone for correct date formatting of the passed in date. |
static java.lang.String |
getShortFormatDate(java.util.Date date,
java.util.Locale locale)
|
FastDateFormat |
getShortTimeFormat()
Returns a short date formatter using the page user's locale and timezone for correct time formatting. |
FastDateFormat |
getTimeFormat()
Returns a date formatter using the page user's locale and timezone for correct time formatting. |
java.util.TimeZone |
getTimeZone()
Returns the page user's time zone. |
static java.lang.String |
localizeDateString(java.lang.String dateString,
java.util.Locale locale)
Converts a generic date string (MM/dd/yyyy) to a localized date string |
static java.util.Date |
parseLocalizedDateString(java.lang.String dateString,
java.util.Locale locale)
Parses a localized date string into a Date |
static java.util.Date |
roundDate(java.util.Date date,
int seconds)
Rounds the given date down to the nearest specified second. |
static long |
roundDate(long date,
int seconds)
Rounds the given date down to the nearest specfied second. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_DATE_PATTERN
public static final java.lang.String DEFAULT_SHORT_DATE_PATTERN
public static final long ONE_DAY_IN_MILLIS
Constructor Detail |
---|
public DateUtils(javax.servlet.http.HttpServletRequest request, User user)
Method Detail |
---|
public java.util.TimeZone getTimeZone()
LocaleUtils.getTimeZone(javax.servlet.http.HttpServletRequest, com.jivesoftware.base.User)
public java.lang.String formatDate(java.util.Date date)
DateFormat.MEDIUM
date and
DateFormat.SHORT
time format is returned.
Locale
,
DateFormat
public java.lang.String getMediumFormatDate()
DateFormat.MEDIUM
date is returned.
Locale
,
DateFormat
public java.lang.String getMediumFormatDate(java.util.Date date)
DateFormat.MEDIUM
date is returned.
Locale
,
DateFormat
public java.lang.String getShortFormatDate()
DateFormat.SHORT
date is returned.
Locale
,
DateFormat
public java.lang.String getShortFormatDate(java.util.Date date)
DateFormat.SHORT
date is returned.
Locale
,
DateFormat
public static java.lang.String getDatePattern()
SimpleDateFormat
class.
By default, DEFAULT_DATE_PATTERN
is returned. You can override this behavior by
setting the date.defaultPattern property in the Jive config file.
public FastDateFormat getDateFormat()
DateFormat.MEDIUM
date and DateFormat.SHORT
time format
is returned.
Locale
,
DateFormat
public FastDateFormat getMediumDateFormat()
DateFormat.MEDIUM
date formatter is returned.
DateFormat
public FastDateFormat getShortDateFormat()
DateFormat.SHORT
date formatter is returned.
DateFormat
public FastDateFormat getTimeFormat()
DateFormat.MEDIUM
time format
is returned.
Locale
,
DateFormat
public FastDateFormat getMediumTimeFormat()
DateFormat.MEDIUM
time formatter is returned.
DateFormat
public FastDateFormat getShortTimeFormat()
DateFormat.SHORT
time formatter is returned.
DateFormat
public static java.util.Date roundDate(java.util.Date date, int seconds)
Date | Seconds | Result |
---|---|---|
1:37.48 | 5 | 1:37.45 |
1:37.48 | 10 | 1:37.40 |
1:37.48 | 30 | 1:37.30 |
1:37.48 | 60 | 1:37.00 |
1:37.48 | 120 | 1:36.00 |
This method is useful when calculating the last post in a forum or the number of new messages from a given date. Using a rounded date allows Jive to internally cache the results of the date query. Here's an example that shows the last posted message in a forum accurate to the last 5 minutess:
ResultFilter filter = new ResultFilter();
filter.setSortOrder(ResultFilter.DESCENDING);
filter.setSortField(JiveConstants.CREATION_DATE);
filter.setCreationDateRangeMin(ResultFilter.roundDate(forum.getModificationDate(), 5*60));
filter.setNumResults(1);
Iterator messages = forum.messages(filter);
ForumMessage lastPost = (ForumMessage)messages.next();
date
- the Date we want to round.seconds
- the number of seconds we want to round the date to.
public static long roundDate(long date, int seconds)
date
- the date (as a long) that we want to round.seconds
- the number of seconds we want to round the date to.
public static java.util.Date getMaxDate()
public static java.lang.String genericizeDateString(java.lang.String dateString, java.util.Locale locale) throws java.text.ParseException
dateString
- localized date string that adheres to the DateFormat
pattern for a Locale
locale
- locale to convert the dateString to
java.text.ParseException
- if the date string does not match the DateFormat
pattern for the user's Locale
public static java.lang.String localizeDateString(java.lang.String dateString, java.util.Locale locale) throws java.text.ParseException
dateString
- date string in the internal format MM/dd/yyyylocale
- the locale to convert the dateString to
DateFormat
pattern for the user's Locale
java.text.ParseException
- if the dateString does not match the internal DateFormat
pattern of MM/dd/yyyypublic static java.util.Date parseLocalizedDateString(java.lang.String dateString, java.util.Locale locale) throws java.text.ParseException
Date
dateString
- localized date string that adheres to the DateFormat
pattern for a Locale
locale
- locale to determine the DateFormat
pattern from
java.text.ParseException
- if the date string does not match the DateFormat
pattern for the user's Locale
public static java.lang.String formatDate(java.util.Date date, java.util.Locale locale)
DateFormat
pattern for the specified Locale
date
- date to formatlocale
- locale to determine DateFormat pattern
public static java.lang.String getShortFormatDate(java.util.Date date, java.util.Locale locale)
protected static java.lang.String convertDateString(java.lang.String dateString, java.lang.String fromPattern, java.lang.String toPattern) throws java.text.ParseException
dateString
- date string to convertfromPattern
- pattern of date stringtoPattern
- pattern to convert date string to
java.text.ParseException
- thrown if dateString doesn't match fromPatternpublic static boolean equalsIgnoreTimestamp(java.util.Date first, java.util.Date second)
first
- second
-
public static long findMidnight(java.util.Date input)
input
-
public static java.util.Calendar findMidnight(java.util.Calendar input)
|
Jive Forums Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |