incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1090888 - in /incubator/isis/trunk/applib/src: main/java/org/apache/isis/applib/ main/java/org/apache/isis/applib/clock/ main/java/org/apache/isis/applib/value/ test/java/org/apache/isis/applib/value/
Date Sun, 10 Apr 2011 20:21:20 GMT
Author: kevin
Date: Sun Apr 10 20:21:20 2011
New Revision: 1090888

URL: http://svn.apache.org/viewvc?rev=1090888&view=rev
Log:
Cleanups. Sync'ed applib.Defaults Calendar with DateTimeZone.

Modified:
    incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/Defaults.java
    incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/clock/Clock.java
    incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Date.java
    incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/DateTime.java
    incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Time.java
    incubator/isis/trunk/applib/src/test/java/org/apache/isis/applib/value/DateTest.java

Modified: incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/Defaults.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/Defaults.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/Defaults.java (original)
+++ incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/Defaults.java Sun Apr
10 20:21:20 2011
@@ -1,18 +1,29 @@
 package org.apache.isis.applib;
 
+import java.util.Calendar;
+
 import org.joda.time.DateTimeZone;
 
 public class Defaults {
-    // {{ ApplibTimeTime
-    static DateTimeZone applibTimeZone = DateTimeZone.UTC;
+    static {
+        setTimeZone(DateTimeZone.UTC);
+    }
+
+    static DateTimeZone timeZone = DateTimeZone.UTC;
 
-    public static DateTimeZone getApplibTimeZone() {
-        return applibTimeZone;
+    public static DateTimeZone getTimeZone() {
+        return timeZone;
     }
 
-    public static void setApplibTimeZone(final DateTimeZone applibTimeZone) {
-        Defaults.applibTimeZone = applibTimeZone;
+    public static void setTimeZone(DateTimeZone timezone) {
+        timeZone = timezone;
+        calendar = Calendar.getInstance(timezone.toTimeZone());
+    }
+
+    private static Calendar calendar;
+
+    public static Calendar getCalendar() {
+        return calendar;
     }
-    // }}
 
 }

Modified: incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/clock/Clock.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/clock/Clock.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/clock/Clock.java (original)
+++ incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/clock/Clock.java Sun
Apr 10 20:21:20 2011
@@ -99,7 +99,7 @@ public abstract class Clock {
     }
 
     public static DateTime getTimeAsDateTime() {
-        return new DateTime(getTime(), Defaults.getApplibTimeZone());
+        return new DateTime(getTime(), Defaults.getTimeZone());
     }
 
     private static void ensureReplaceable() {

Modified: incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Date.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Date.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Date.java (original)
+++ incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Date.java Sun Apr
10 20:21:20 2011
@@ -19,8 +19,6 @@
 
 package org.apache.isis.applib.value;
 
-import java.util.Calendar;
-
 import org.joda.time.DateTime;
 import org.joda.time.DateTimeFieldType;
 import org.joda.time.Period;
@@ -51,12 +49,8 @@ public class Date extends Magnitude<Date
      * Create a Date object for today's date.
      */
     public Date() {
-        Calendar time = Clock.getTimeAsCalendar();
-        time.set(Calendar.HOUR_OF_DAY, 0);
-        time.set(Calendar.MINUTE, 0);
-        time.set(Calendar.SECOND, 0);
-        time.set(Calendar.MILLISECOND, 0);
-        date = new DateTime(time.getTime(), Defaults.getApplibTimeZone());
+        DateTime time = Clock.getTimeAsDateTime().withTime(0, 0, 0, 0);
+        date = new DateTime(time, Defaults.getTimeZone());
     }
 
     /**
@@ -71,7 +65,7 @@ public class Date extends Magnitude<Date
      * Create a Date object based on the specified Java date object. The time portion of
the Java date is disposed of.
      */
     public Date(final java.util.Date date) {
-        this.date = new DateTime(date.getTime(), Defaults.getApplibTimeZone());
+        this.date = new DateTime(date.getTime(), Defaults.getTimeZone());
     }
 
     public Date(final long millisSinceEpoch) {
@@ -83,7 +77,7 @@ public class Date extends Magnitude<Date
     }
 
     private DateTime newDateTime(int year, int month, int day) {
-        return new DateTime(year, month, day, 0, 0, 0, 0, Defaults.getApplibTimeZone());
+        return new DateTime(year, month, day, 0, 0, 0, 0, Defaults.getTimeZone());
     }
 
     protected Date createDate(final DateTime date) {
@@ -284,6 +278,8 @@ public class Date extends Magnitude<Date
 
     @Override
     public String toString() {
-        return getYear() + "-" + getMonth() + "-" + getDay();
+        // return getYear() + "-" + getMonth() + "-" + getDay();
+        return String.format("%04d-%02d-%02d", getYear(), getMonth(), getDay());
+
     }
 }

Modified: incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/DateTime.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/DateTime.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/DateTime.java (original)
+++ incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/DateTime.java Sun
Apr 10 20:21:20 2011
@@ -44,7 +44,7 @@ public class DateTime extends Magnitude<
      * Create a Time object for storing a timeStamp set to the current time.
      */
     public DateTime() {
-        org.joda.time.DateTime d = new org.joda.time.DateTime(Clock.getTime(), Defaults.getApplibTimeZone());
+        org.joda.time.DateTime d = new org.joda.time.DateTime(Clock.getTime(), Defaults.getTimeZone());
         // dateTime = d.secondOfMinute().setCopy(0);
         dateTime = d;
     }
@@ -56,11 +56,11 @@ public class DateTime extends Magnitude<
      * @param date
      */
     public DateTime(final Date date) {
-        this.dateTime = new org.joda.time.DateTime(date, Defaults.getApplibTimeZone());
+        this.dateTime = new org.joda.time.DateTime(date, Defaults.getTimeZone());
     }
 
     public DateTime(final long millisSinceEpoch) {
-        this.dateTime = new org.joda.time.DateTime(millisSinceEpoch, Defaults.getApplibTimeZone());
+        this.dateTime = new org.joda.time.DateTime(millisSinceEpoch, Defaults.getTimeZone());
     }
 
     public DateTime(final Date date, TimeZone timeZone) {
@@ -83,7 +83,7 @@ public class DateTime extends Magnitude<
         checkTime(year, month, day, 0, 0);
         dateTime =
             new org.joda.time.DateTime(year, month, day, time.getHour(), time.getMinute(),
time.getSecond(), 0,
-                Defaults.getApplibTimeZone());
+                Defaults.getTimeZone());
     }
 
     /**
@@ -98,7 +98,7 @@ public class DateTime extends Magnitude<
      */
     public DateTime(final int year, final int month, final int day, final int hour, final
int minute, final int second) {
         checkTime(year, month, day, hour, minute);
-        dateTime = new org.joda.time.DateTime(year, month, day, hour, minute, second, 0,
Defaults.getApplibTimeZone());
+        dateTime = new org.joda.time.DateTime(year, month, day, hour, minute, second, 0,
Defaults.getTimeZone());
     }
 
     private void checkTime(final int year, final int month, final int day, final int hour,
final int minute) {
@@ -178,6 +178,15 @@ public class DateTime extends Magnitude<
     }
 
     /**
+     * Day of year (1 to 365 [366 in leap years]) for Gregorian calendar.
+     * 
+     * @return
+     */
+    public int getDayOfYear() {
+        return dateTime.getDayOfYear();
+    }
+
+    /**
      * A DateTime that is at the start of the current week. Time is preserved.
      */
     public DateTime startOfWeek() {
@@ -199,15 +208,6 @@ public class DateTime extends Magnitude<
     }
 
     /**
-     * Day of year (1 to 365 [366 in leap years]) for Gregorian calendar.
-     * 
-     * @return
-     */
-    public int getDayOfYear() {
-        return dateTime.getDayOfYear();
-    }
-
-    /**
      * returns true if the time stamp of this object has the same value as the specified
time
      */
     @Override

Modified: incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Time.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Time.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Time.java (original)
+++ incubator/isis/trunk/applib/src/main/java/org/apache/isis/applib/value/Time.java Sun Apr
10 20:21:20 2011
@@ -61,7 +61,7 @@ public class Time extends Magnitude<Time
     }
 
     private DateTime newDateTime(final int hourOfDay, final int minuteOfHour, final int secondsOfMinute)
{
-        return new DateTime(1970, 1, 1, hourOfDay, minuteOfHour, secondsOfMinute, 0, Defaults.getApplibTimeZone());
+        return new DateTime(1970, 1, 1, hourOfDay, minuteOfHour, secondsOfMinute, 0, Defaults.getTimeZone());
     }
 
     /**
@@ -85,7 +85,7 @@ public class Time extends Magnitude<Time
      */
     public Time(final java.sql.Date date) {
 
-        this.time = new DateTime(date.getTime(), Defaults.getApplibTimeZone());
+        this.time = new DateTime(date.getTime(), Defaults.getTimeZone());
     }
 
     /**
@@ -111,7 +111,7 @@ public class Time extends Magnitude<Time
      * Create a new Time object from the millisSinceEpoch, using UTC.
      */
     public Time(long millisSinceEpoch) {
-        this.time = new DateTime(millisSinceEpoch, Defaults.getApplibTimeZone());
+        this.time = new DateTime(millisSinceEpoch, Defaults.getTimeZone());
     }
 
     /**

Modified: incubator/isis/trunk/applib/src/test/java/org/apache/isis/applib/value/DateTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/applib/src/test/java/org/apache/isis/applib/value/DateTest.java?rev=1090888&r1=1090887&r2=1090888&view=diff
==============================================================================
--- incubator/isis/trunk/applib/src/test/java/org/apache/isis/applib/value/DateTest.java (original)
+++ incubator/isis/trunk/applib/src/test/java/org/apache/isis/applib/value/DateTest.java Sun
Apr 10 20:21:20 2011
@@ -144,13 +144,12 @@ public class DateTest {
         assertEquals(new Date(2000, 3, 13), actual.startOfWeek());
         assertEquals(new Date(2000, 2, 28), new Date(2000, 3, 2).startOfWeek());
     }
-    
+
     @Test
     public void testEndOfMonth() {
         assertEquals(new Date(2000, 2, 29), new Date(2000, 2, 2).endOfMonth());
         assertEquals(new Date(2001, 2, 28), new Date(2001, 2, 2).endOfMonth());
     }
-    
 
     @Test
     public void testNewWithTodaysDate() {
@@ -161,7 +160,7 @@ public class DateTest {
 
     @Test
     public void testToString() {
-        assertEquals("2000-3-14", actual.toString());
+        assertEquals("2000-03-14", actual.toString());
     }
 
 }



Mime
View raw message