X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;fp=src%2Fjalview%2Fbin%2FCache.java;h=76fdb695563a70fd462064dc84b35f37157ecb02;hb=e8ab1b32267d78c12e9ec2db2a65cf1b472fe1d0;hp=4be78302bbacc10b62ed83a86438be1a081c927d;hpb=92fd3e4d77444c14bb899e9fcd07bd8d44fe7b1e;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 4be7830..76fdb69 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -38,6 +38,7 @@ import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import java.util.Enumeration; +import java.util.Locale; import java.util.Properties; import java.util.TreeSet; @@ -237,6 +238,15 @@ public class Cache private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER .toString(); + /* + * a date formatter using a fixed (rather than the user's) locale; + * this ensures that date properties can be written and re-read successfully + * even if the user changes their locale setting + */ + private static final DateFormat date_format = SimpleDateFormat + .getDateTimeInstance(SimpleDateFormat.LONG, + SimpleDateFormat.LONG, Locale.UK); + /** * Initialises the Jalview Application Log */ @@ -884,31 +894,32 @@ public class Cache { setProperty(property, jalview.util.Format.getHexString(colour)); } - - public static final DateFormat date_format = SimpleDateFormat - .getDateTimeInstance(); - + /** - * store a date in a jalview property + * Stores a formatted date in a jalview property, using a fixed locale. * - * @param string - * @param time + * @param propertyName + * @param date + * @return the formatted date string */ - public static void setDateProperty(String property, Date time) + public static String setDateProperty(String propertyName, Date date) { - setProperty(property, date_format.format(time)); + String formatted = date_format.format(date); + setProperty(propertyName, formatted); + return formatted; } /** - * read a date stored in a jalview property + * Reads a date stored in a Jalview property, parses it (using a fixed locale + * format) and returns as a Date, or null if parsing fails * - * @param property - * @return valid date as stored by setDateProperty, or null + * @param propertyName + * @return * */ - public static Date getDateProperty(String property) + public static Date getDateProperty(String propertyName) { - String val = getProperty(property); + String val = getProperty(propertyName); if (val != null) { try @@ -917,7 +928,7 @@ public class Cache } catch (Exception ex) { System.err.println("Invalid or corrupt date in property '" - + property + "' : value was '" + val + "'"); + + propertyName + "' : value was '" + val + "'"); } } return null;