You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/05/06 20:27:00 UTC

[commons-beanutils] branch master updated (41ee9994 -> 0fbc23ff)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git


    from 41ee9994 Backstop for other TemporalAccessor implementations.
     new 1536e880 Remove Java < 1.4 workaround.
     new 0fbc23ff Update test framework method for java.sql.Date.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../converters/DateConverterTestBase.java          | 31 +++++++++++-----------
 1 file changed, 16 insertions(+), 15 deletions(-)


[commons-beanutils] 02/02: Update test framework method for java.sql.Date.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git

commit 0fbc23ff1ba7945d3c06403396f932c3dc6a915d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 6 16:26:55 2022 -0400

    Update test framework method for java.sql.Date.
---
 .../beanutils2/converters/DateConverterTestBase.java        | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java b/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
index f6435fc6..70ff839e 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
@@ -29,6 +29,7 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
+import java.util.Objects;
 
 import org.apache.commons.beanutils2.ConversionException;
 import org.apache.commons.beanutils2.Converter;
@@ -57,11 +58,15 @@ public abstract class DateConverterTestBase<T> extends TestCase {
     protected abstract Class<T> getExpectedType();
 
     /**
-     * Convert a Date or Calendar objects to the time in milliseconds
+     * Converts a Date or Calendar objects to the time in milliseconds
      * @param date The date or calendar object
      * @return The time in milliseconds
      */
     long getTimeInMillis(final Object date) {
+        if (date instanceof java.sql.Date) {
+            return ((java.sql.Date) date).getTime();
+        }
+
         if (date instanceof java.sql.Timestamp) {
             return ((java.sql.Timestamp) date).getTime();
         }
@@ -85,7 +90,11 @@ public abstract class DateConverterTestBase<T> extends TestCase {
         if (date instanceof Calendar) {
             return ((Calendar) date).getTime().getTime();
         }
-        return ((Date) date).getTime();
+
+        if (date instanceof Date) {
+            return ((Date) date).getTime();
+        }
+        throw new IllegalArgumentException(Objects.toString(date));
     }
 
     /**


[commons-beanutils] 01/02: Remove Java < 1.4 workaround.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git

commit 1536e880242186cd63f4967199c793f9401fbb3d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 6 16:13:46 2022 -0400

    Remove Java < 1.4 workaround.
---
 .../converters/DateConverterTestBase.java          | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java b/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
index 37dcd3ef..f6435fc6 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/DateConverterTestBase.java
@@ -62,38 +62,30 @@ public abstract class DateConverterTestBase<T> extends TestCase {
      * @return The time in milliseconds
      */
     long getTimeInMillis(final Object date) {
-
         if (date instanceof java.sql.Timestamp) {
-
-            // N.B. Prior to JDK 1.4 the Timestamp's getTime() method
-            //      didn't include the milliseconds. The following code
-            //      ensures it works consistently across JDK versions
-            final java.sql.Timestamp timestamp = (java.sql.Timestamp)date;
-            long timeInMillis = timestamp.getTime() / 1000 * 1000;
-            timeInMillis += timestamp.getNanos() / 1000000;
-            return timeInMillis;
+            return ((java.sql.Timestamp) date).getTime();
         }
 
         if (date instanceof LocalDate) {
-            return  ((LocalDate)date).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
+            return ((LocalDate) date).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
         }
 
         if (date instanceof LocalDateTime) {
-            return  ((LocalDateTime)date).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+            return ((LocalDateTime) date).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
         }
 
         if (date instanceof ZonedDateTime) {
-            return  ((ZonedDateTime)date).toInstant().toEpochMilli();
+            return ((ZonedDateTime) date).toInstant().toEpochMilli();
         }
 
         if (date instanceof OffsetDateTime) {
-            return  ((OffsetDateTime)date).toInstant().toEpochMilli();
+            return ((OffsetDateTime) date).toInstant().toEpochMilli();
         }
 
         if (date instanceof Calendar) {
-            return ((Calendar)date).getTime().getTime();
+            return ((Calendar) date).getTime().getTime();
         }
-        return ((Date)date).getTime();
+        return ((Date) date).getTime();
     }
 
     /**