polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [29/50] [abbrv] zest-qi4j git commit: Replaced Joda Time with Java 8 Time API.
Date Fri, 17 Apr 2015 16:08:41 GMT
http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/actions/IndexAction.java
----------------------------------------------------------------------
diff --git a/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/actions/IndexAction.java
b/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/actions/IndexAction.java
index 49a0c52..15495ad 100644
--- a/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/actions/IndexAction.java
+++ b/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/actions/IndexAction.java
@@ -20,12 +20,11 @@ package org.qi4j.library.struts2.example.actions;
 import com.opensymphony.xwork2.ActionSupport;
 import com.opensymphony.xwork2.conversion.annotations.Conversion;
 import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+import java.time.Instant;
 import org.apache.struts2.config.Result;
 import org.qi4j.api.injection.scope.Structure;
 import org.qi4j.api.structure.Module;
 
-import java.util.Date;
-
 @Conversion
 @Result( value = "/jsp/index.jsp" )
 public class IndexAction
@@ -37,15 +36,15 @@ public class IndexAction
     @Structure
     private Module module;
 
-    private Date now;
+    private Instant now;
 
     public IndexAction()
     {
-        now = new Date();
+        now = Instant.now();
     }
 
     @TypeConversion( converter = "org.qi4j.library.struts2.example.converters.DateConverter"
)
-    public Date getDateNow()
+    public Instant getDateNow()
     {
         return now;
     }
@@ -59,7 +58,7 @@ public class IndexAction
     public String execute()
         throws Exception
     {
-        now = new Date();
+        now = Instant.now();
         return SUCCESS;
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/converters/DateConverter.java
----------------------------------------------------------------------
diff --git a/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/converters/DateConverter.java
b/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/converters/DateConverter.java
index 1a28fb3..f5cbb06 100644
--- a/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/converters/DateConverter.java
+++ b/samples/struts2Hello/src/main/java/org/qi4j/library/struts2/example/converters/DateConverter.java
@@ -17,12 +17,9 @@
  */
 package org.qi4j.library.struts2.example.converters;
 
-import org.apache.struts2.util.StrutsTypeConverter;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.ZonedDateTime;
 import java.util.Map;
+import org.apache.struts2.util.StrutsTypeConverter;
 
 public class DateConverter
     extends StrutsTypeConverter
@@ -32,12 +29,11 @@ public class DateConverter
     {
         if( values != null && values.length > 0 && values[ 0 ] != null
&& values[ 0 ].length() > 0 )
         {
-            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
             try
             {
-                return sdf.parse( values[ 0 ] );
+                return ZonedDateTime.parse( values[ 0 ] );
             }
-            catch( ParseException e )
+            catch( RuntimeException e )
             {
                 throw new IllegalArgumentException( "Parse [" + values[ 0 ] + "] do date
fail.", e );
             }
@@ -48,10 +44,9 @@ public class DateConverter
     @Override
     public String convertToString( Map context, Object o )
     {
-        if( o instanceof Date )
+        if( o instanceof ZonedDateTime )
         {
-            SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
-            return sdf.format( (Date) o );
+            return o.toString();
         }
         return "";
     }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/tutorials/introduction/thirtyminutes/src/main/java/org/qi4j/demo/thirtyminutes/ThirtyMinutesDocs.java
----------------------------------------------------------------------
diff --git a/tutorials/introduction/thirtyminutes/src/main/java/org/qi4j/demo/thirtyminutes/ThirtyMinutesDocs.java
b/tutorials/introduction/thirtyminutes/src/main/java/org/qi4j/demo/thirtyminutes/ThirtyMinutesDocs.java
index e125b6d..3221847 100644
--- a/tutorials/introduction/thirtyminutes/src/main/java/org/qi4j/demo/thirtyminutes/ThirtyMinutesDocs.java
+++ b/tutorials/introduction/thirtyminutes/src/main/java/org/qi4j/demo/thirtyminutes/ThirtyMinutesDocs.java
@@ -2,8 +2,7 @@ package org.qi4j.demo.thirtyminutes;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.util.Calendar;
-import java.util.Date;
+import java.time.LocalDate;
 import java.util.Iterator;
 import java.util.List;
 import org.qi4j.api.common.Optional;
@@ -81,10 +80,7 @@ public class ThirtyMinutesDocs
 // START SNIPPET: 7
         QueryBuilder<Order> builder = module.newQueryBuilder( Order.class );
 
-        Calendar cal = Calendar.getInstance();
-        cal.setTime( new Date() );
-        cal.roll( Calendar.DAY_OF_MONTH, -90 );
-        Date last90days = cal.getTime();
+        LocalDate last90days = LocalDate.now().minusDays( 90 );
         Order template = templateFor( Order.class );
         builder.where( gt( template.createdDate(), last90days ) );
         Query<Order> query = uow.newQuery(builder);
@@ -103,10 +99,7 @@ public class ThirtyMinutesDocs
 // START SNIPPET: 8
         QueryBuilder<HasCustomer> builder = module.newQueryBuilder( HasCustomer.class
);
 
-        Calendar cal = Calendar.getInstance();
-        cal.setTime( new Date() );
-        cal.roll( Calendar.MONTH, -1 );
-        Date lastMonth = cal.getTime();
+        LocalDate lastMonth = LocalDate.now().minusMonths( 1 );
         Order template1 = templateFor( Order.class );
         builder.where( gt( template1.createdDate(), lastMonth ) );
         Query<HasCustomer> query = uow.newQuery(builder);
@@ -127,7 +120,7 @@ public class ThirtyMinutesDocs
 
         void completed();
 
-        Property<Date> createdDate();
+        Property<LocalDate> createdDate();
     }
 
 


Mime
View raw message