You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/06/11 19:08:10 UTC

incubator-groovy git commit: GROOVY-7462: Dates factory fix when initializing miliseconds field

Repository: incubator-groovy
Updated Branches:
  refs/heads/master e91bb9877 -> f03d7357e


GROOVY-7462: Dates factory fix when initializing miliseconds field


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/f03d7357
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/f03d7357
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/f03d7357

Branch: refs/heads/master
Commit: f03d7357e4c20a7e935434127742d92d69610d57
Parents: e91bb98
Author: Fabio de Matos <fd...@despegar.com>
Authored: Wed Jun 10 12:18:10 2015 -0300
Committer: pascalschumacher <pa...@gmx.net>
Committed: Thu Jun 11 19:07:37 2015 +0200

----------------------------------------------------------------------
 .../main/java/groovy/json/internal/Dates.java   | 16 +----------
 .../groovy/json/internal/DatesTest.groovy       | 30 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/f03d7357/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
index e217c7d..cdde3f7 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
@@ -37,20 +37,6 @@ public class Dates {
         return utcNow;
     }
 
-    private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second) {
-        Calendar calendar = Calendar.getInstance();
-
-        calendar.set(Calendar.YEAR, year);
-        calendar.set(Calendar.MONTH, month - 1);
-        calendar.set(Calendar.DAY_OF_MONTH, day);
-        calendar.set(Calendar.HOUR_OF_DAY, hour);
-        calendar.set(Calendar.MINUTE, minute);
-        calendar.set(Calendar.SECOND, second);
-        calendar.setTimeZone(tz);
-
-        return calendar.getTime();
-    }
-
     private static Date internalDate(TimeZone tz, int year, int month, int day, int hour,
                                      int minute, int second, int miliseconds) {
 
@@ -71,7 +57,7 @@ public class Dates {
 
     public static Date toDate(TimeZone tz, int year, int month, int day,
                               int hour, int minute, int second) {
-        return internalDate(tz, year, month, day, hour, minute, second);
+        return internalDate(tz, year, month, day, hour, minute, second, 0);
     }
 
     public static Date toDate(TimeZone tz, int year, int month, int day,

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/f03d7357/subprojects/groovy-json/src/test/groovy/groovy/json/internal/DatesTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/test/groovy/groovy/json/internal/DatesTest.groovy b/subprojects/groovy-json/src/test/groovy/groovy/json/internal/DatesTest.groovy
new file mode 100644
index 0000000..1bb97f5
--- /dev/null
+++ b/subprojects/groovy-json/src/test/groovy/groovy/json/internal/DatesTest.groovy
@@ -0,0 +1,30 @@
+package groovy.json.internal
+
+
+class DatesTest extends GroovyTestCase{
+
+    // GROOVY-7462
+    void testDatesFactory() {
+        Date d1 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59)
+
+        Thread.sleep(1) // lets get some time between calling constructors
+
+        Date d2 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59)
+
+        assert d1 == d2
+    }
+
+    void testDatesFactoryWithDefaultMs() {
+        Date d1 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59,0)
+        Date d2 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59)
+
+        assert d1 == d2
+    }
+
+    void testDatesFactoryEnforceDefaultMs() {
+        Date d1 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59,1)
+        Date d2 = Dates.toDate(TimeZone.getTimeZone("GMT"),2015,06,07,23,55,59)
+
+        assert d1 != d2
+    }
+}