Commit 1e3e974e authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added #formatTime for formating time. :)


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1438 b35dd754-fafc-0310-a699-88a17e54d16e
parent ac9bb0c1
...@@ -64,6 +64,7 @@ public class JiveGlobals { ...@@ -64,6 +64,7 @@ public class JiveGlobals {
private static TimeZone timeZone = null; private static TimeZone timeZone = null;
private static DateFormat dateFormat = null; private static DateFormat dateFormat = null;
private static DateFormat dateTimeFormat = null; private static DateFormat dateTimeFormat = null;
private static DateFormat timeFormat = null;
/** /**
* Returns the global Locale used by Jive. A locale specifies language * Returns the global Locale used by Jive. A locale specifies language
...@@ -120,9 +121,11 @@ public class JiveGlobals { ...@@ -120,9 +121,11 @@ public class JiveGlobals {
setXMLProperty("locale", locale.toString()); setXMLProperty("locale", locale.toString());
// Reset the date formatter objects // Reset the date formatter objects
timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, locale); DateFormat.MEDIUM, locale);
timeFormat.setTimeZone(timeZone);
dateFormat.setTimeZone(timeZone); dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone); dateTimeFormat.setTimeZone(timeZone);
} }
...@@ -157,11 +160,33 @@ public class JiveGlobals { ...@@ -157,11 +160,33 @@ public class JiveGlobals {
*/ */
public static void setTimeZone(TimeZone newTimeZone) { public static void setTimeZone(TimeZone newTimeZone) {
timeZone = newTimeZone; timeZone = newTimeZone;
timeFormat.setTimeZone(timeZone);
dateFormat.setTimeZone(timeZone); dateFormat.setTimeZone(timeZone);
dateTimeFormat.setTimeZone(timeZone); dateTimeFormat.setTimeZone(timeZone);
setProperty("locale.timeZone", timeZone.getID()); setProperty("locale.timeZone", timeZone.getID());
} }
/**
* Formats a Date object to return a time using the global locale.
*
* @param date the Date to format.
* @return a String representing the time.
*/
public static String formatTime(Date date) {
if (timeFormat == null) {
if (properties != null) {
timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
timeFormat.setTimeZone(getTimeZone());
}
else {
DateFormat instance = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
instance.setTimeZone(getTimeZone());
return instance.format(date);
}
}
return timeFormat.format(date);
}
/** /**
* Formats a Date object to return a date using the global locale. * Formats a Date object to return a date using the global locale.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment