db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bouschen <mbo.t...@spree.de>
Subject Re: Patch for date issue
Date Fri, 08 Jul 2005 17:36:44 GMT
Hi Craig,

I tried your patch and it works with my environment using German as the 
default locale.

Regards Michael

>------------------------------------------------------------------------
>
>Index: test/java/javax/jdo/identity/ObjectIdentityTest.java
>===================================================================
>--- test/java/javax/jdo/identity/ObjectIdentityTest.java	(revision 209692)
>+++ test/java/javax/jdo/identity/ObjectIdentityTest.java	(working copy)
>@@ -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,10 +220,21 @@
>     }
> 
>     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() {
>         try {
>             ObjectIdentity c1 = new ObjectIdentity(Object.class, 
>Index: src/java/javax/jdo/spi/JDOImplHelper.java
>===================================================================
>--- src/java/javax/jdo/spi/JDOImplHelper.java	(revision 209692)
>+++ src/java/javax/jdo/spi/JDOImplHelper.java	(working copy)
>@@ -89,14 +89,20 @@
>      */
>     private final static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle");
//NOI18N
>     
>+    /** The DateFormat pattern.
>+     */
>+    private static String dateFormatPattern;
>+
>     /** The default DateFormat instance.
>      */
>-    static DateFormat dateFormat = DateFormat.getDateTimeInstance();
>+    private static DateFormat dateFormat;
> 
>-    /** The DateFormat pattern, set to the default.
>+    /** Register the default DateFormat instance.
>      */
>-    static String dateFormatPattern = "MMM d, yyyy hh:mm:ss a";  //NOI18N
>-
>+    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();
>  
>
>
> ------------------------------------------------------------------------
>
>
> Craig Russell
>
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
>
> 408 276-5638 mailto:Craig.Russell@sun.com
>
> P.S. A good JDO? O, Gasp!
>
>


-- 
Michael Bouschen		Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de	http://www.tech.spree.de/
Tel.:++49/30/235 520-33		Buelowstr. 66			
Fax.:++49/30/2175 2012		D-10783 Berlin			


Mime
View raw message