You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by cl...@apache.org on 2005/07/08 23:04:31 UTC
svn commit: r209889 - in /incubator/jdo/trunk/api20:
src/java/javax/jdo/spi/JDOImplHelper.java
test/java/javax/jdo/identity/ObjectIdentityTest.java
Author: clr
Date: Fri Jul 8 14:04:29 2005
New Revision: 209889
URL: http://svn.apache.org/viewcvs?rev=209889&view=rev
Log:
fixed Date constructor issue with non-US locales
Modified:
incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java
Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java?rev=209889&r1=209888&r2=209889&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java Fri Jul 8 14:04:29 2005
@@ -89,14 +89,20 @@
*/
private final static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle"); //NOI18N
- /** The default DateFormat instance.
+ /** The DateFormat pattern.
*/
- static DateFormat dateFormat = DateFormat.getDateTimeInstance();
+ private static String dateFormatPattern;
- /** The DateFormat pattern, set to the default.
+ /** The default DateFormat instance.
*/
- static String dateFormatPattern = "MMM d, yyyy hh:mm:ss a"; //NOI18N
+ private static DateFormat dateFormat;
+ /** Register the default DateFormat instance.
+ */
+ static {
+ jdoImplHelper.registerDateFormat(DateFormat.getDateTimeInstance());
+ }
+
/** Creates new JDOImplHelper */
private JDOImplHelper() {
}
@@ -631,7 +637,7 @@
* for error messages.
* @param df the DateFormat instance to use
*/
- synchronized void registerDateFormat(DateFormat df) {
+ public synchronized void registerDateFormat(DateFormat df) {
dateFormat = df;
if (df instanceof SimpleDateFormat) {
dateFormatPattern = ((SimpleDateFormat)df).toPattern();
Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java?rev=209889&r1=209888&r2=209889&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java Fri Jul 8 14:04:29 2005
@@ -27,12 +27,22 @@
import java.io.Serializable;
import java.math.BigDecimal;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+
import java.util.Currency;
import java.util.Date;
import java.util.Locale;
import javax.jdo.JDOUserException;
import javax.jdo.JDONullIdentityException;
+
+import javax.jdo.spi.JDOImplHelper;
+
import javax.jdo.util.BatchTestRunner;
/**
@@ -40,6 +50,17 @@
*/
public class ObjectIdentityTest extends SingleFieldIdentityTest {
+ /** The JDOImplHelper instance used for Date formatting.
+ */
+ private static JDOImplHelper helper = (JDOImplHelper)
+ AccessController.doPrivileged(
+ new PrivilegedAction () {
+ public Object run () {
+ return JDOImplHelper.getInstance();
+ }
+ }
+ );
+
/** Creates a new instance of ObjectIdentityTest */
public ObjectIdentityTest() {
}
@@ -199,8 +220,19 @@
}
public void testStringDateConstructor() {
+ SimpleDateFormat usDateFormat = new SimpleDateFormat
+ ("MMM dd, yyyy hh:mm:ss a", Locale.US);
+ helper.registerDateFormat(usDateFormat);
Object c1 = new ObjectIdentity(Object.class,
"java.util.Date:Jan 01, 1970 00:00:00 AM");
+ helper.registerDateFormat(DateFormat.getDateTimeInstance());
+ }
+
+ public void testStringDefaultDateConstructor() {
+ DateFormat dateFormat = DateFormat.getDateTimeInstance();
+ String rightNow = dateFormat.format(new Date());
+ Object c1 = new ObjectIdentity(Object.class,
+ "java.util.Date:" + rightNow);
}
public void testBadStringDateConstructor() {