diff options
author | Patrick Tasse | 2014-09-18 18:36:21 +0000 |
---|---|---|
committer | Patrick Tasse | 2014-09-23 17:45:44 +0000 |
commit | e96acf041b88f2fcf1466d58301c8d1d28806e50 (patch) | |
tree | 5f14c74c5a0fb9810529ce268b16b9550144a4c6 /lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf | |
parent | c6168352e50fbfbff000a9ffc62aacf45138e931 (diff) | |
download | org.eclipse.linuxtools-e96acf041b88f2fcf1466d58301c8d1d28806e50.tar.gz org.eclipse.linuxtools-e96acf041b88f2fcf1466d58301c8d1d28806e50.tar.xz org.eclipse.linuxtools-e96acf041b88f2fcf1466d58301c8d1d28806e50.zip |
tmf: Support locale in timestamp format and time preferences
Bug: 439917
Change-Id: I14b90bed61ed0f6174f27852fa7fad72bfa5d41e
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/33576
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf')
3 files changed, 48 insertions, 5 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/ITmfTimePreferencesConstants.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/ITmfTimePreferencesConstants.java index a0c6af21b4..5ca9b175d9 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/ITmfTimePreferencesConstants.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/ITmfTimePreferencesConstants.java @@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.timestamp; /** * @since 2.1 + * @noimplement This interface is not intended to be implemented by clients. */ @SuppressWarnings({ "javadoc", "nls" }) public interface ITmfTimePreferencesConstants { @@ -52,4 +53,6 @@ public interface ITmfTimePreferencesConstants { public static final String DELIMITER_DQUOT = "\""; /** @since 3.0 */ public static final String DELIMITER_QUOTE = "''"; + /** @since 3.1 */ + public static final String LOCALE = TIME_FORMAT_PREF + ".locale"; } diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java index be8e17d31f..4bc9b5c295 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimePreferences.java @@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.timestamp; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.TimeZone; @@ -119,6 +120,16 @@ public class TmfTimePreferences { } /** + * Get the locale + * + * @return the locale + * @since 3.1 + */ + public Locale getLocale() { + return Locale.forLanguageTag(Platform.getPreferencesService().getString(Activator.PLUGIN_ID, ITmfTimePreferencesConstants.LOCALE, Locale.getDefault().toLanguageTag(), null)); + } + + /** * Get the default preferences map * * @return a collection containing the default preferences diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java index 3259c150e8..b1ea773a5a 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimestampFormat.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.TimeZone; /** @@ -207,6 +208,9 @@ public class TmfTimestampFormat extends SimpleDateFormat { // The list of supplementary patterns private List<String> fSupplPatterns = new ArrayList<>(); + // The locale + private final Locale fLocale; + /** * The supplementary pattern letters. Can be redefined by sub-classes * to either override existing letters or augment the letter set. @@ -253,6 +257,7 @@ public class TmfTimestampFormat extends SimpleDateFormat { * @param pattern the format pattern */ public TmfTimestampFormat(String pattern) { + fLocale = Locale.getDefault(); applyPattern(pattern); } @@ -264,7 +269,24 @@ public class TmfTimestampFormat extends SimpleDateFormat { * @since 2.1 */ public TmfTimestampFormat(String pattern, TimeZone timeZone) { + fLocale = Locale.getDefault(); + setTimeZone(timeZone); + applyPattern(pattern); + } + + /** + * The fuller constructor + * + * @param pattern the format pattern + * @param timeZone the time zone + * @param locale the locale + * @since 3.1 + */ + public TmfTimestampFormat(String pattern, TimeZone timeZone, Locale locale) { + super("", locale); //$NON-NLS-1$ + fLocale = locale; setTimeZone(timeZone); + setCalendar(Calendar.getInstance(timeZone, locale)); applyPattern(pattern); } @@ -274,7 +296,7 @@ public class TmfTimestampFormat extends SimpleDateFormat { * @param other the other format pattern */ public TmfTimestampFormat(TmfTimestampFormat other) { - this(other.fPattern); + this(other.fPattern, other.getTimeZone(), other.fLocale); } // ------------------------------------------------------------------------ @@ -285,7 +307,10 @@ public class TmfTimestampFormat extends SimpleDateFormat { * @since 2.1 */ public static void updateDefaultFormats() { - fDefaultTimeFormat = new TmfTimestampFormat(TmfTimePreferences.getInstance().getTimePattern(), TmfTimePreferences.getInstance().getTimeZone()); + fDefaultTimeFormat = new TmfTimestampFormat( + TmfTimePreferences.getInstance().getTimePattern(), + TmfTimePreferences.getInstance().getTimeZone(), + TmfTimePreferences.getInstance().getLocale()); fDefaultIntervalFormat = new TmfTimestampFormat(TmfTimePreferences.getInstance().getIntervalPattern()); } @@ -294,7 +319,10 @@ public class TmfTimestampFormat extends SimpleDateFormat { */ public static TmfTimestampFormat getDefaulTimeFormat() { if (fDefaultTimeFormat == null) { - fDefaultTimeFormat = new TmfTimestampFormat(TmfTimePreferences.getInstance().getTimePattern(), TmfTimePreferences.getInstance().getTimeZone()); + fDefaultTimeFormat = new TmfTimestampFormat( + TmfTimePreferences.getInstance().getTimePattern(), + TmfTimePreferences.getInstance().getTimeZone(), + TmfTimePreferences.getInstance().getLocale()); } return fDefaultTimeFormat; } @@ -464,9 +492,9 @@ public class TmfTimestampFormat extends SimpleDateFormat { getCalendar(); if (ref != Long.MIN_VALUE) { - Calendar baseTime = Calendar.getInstance(getTimeZone()); + Calendar baseTime = Calendar.getInstance(getTimeZone(), fLocale); baseTime.setTimeInMillis(baseDate.getTime()); - Calendar newTime = Calendar.getInstance(getTimeZone()); + Calendar newTime = Calendar.getInstance(getTimeZone(), fLocale); newTime.setTimeInMillis(ref / 1000000); boolean setRemainingFields = false; if (dateTimePatternContains("yY")) { //$NON-NLS-1$ @@ -506,6 +534,7 @@ public class TmfTimestampFormat extends SimpleDateFormat { if (setRemainingFields || dateTimePatternContains("s")) { //$NON-NLS-1$ newTime.set(Calendar.SECOND, baseTime.get(Calendar.SECOND)); } + newTime.set(Calendar.MILLISECOND, 0); seconds = newTime.getTimeInMillis() / 1000; } else { seconds = baseDate.getTime() / 1000; |