← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2397: Implemented simple iso string format representation of period for non-exotic period types plus so...

 

------------------------------------------------------------
revno: 2397
committer: Bob Joliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2010-12-20 12:43:44 +0000
message:
  Implemented simple iso string format representation of period for non-exotic period types plus some simple tests.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SurveyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -131,4 +133,11 @@
 
         return days;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+        return format.format( period.getStartDate());
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java	2010-11-26 11:02:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java	2010-12-20 12:43:44 +0000
@@ -144,4 +144,10 @@
 
         return years;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        throw new UnsupportedOperationException( "Not supported yet." );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -43,6 +44,7 @@
 public class MonthlyPeriodType
     extends CalendarPeriodType
 {
+
     /**
      * The name of the MonthlyPeriodType, which is "Monthly".
      */
@@ -53,7 +55,6 @@
     // -------------------------------------------------------------------------
     // PeriodType functionality
     // -------------------------------------------------------------------------
-
     @Override
     public String getName()
     {
@@ -92,7 +93,6 @@
     // -------------------------------------------------------------------------
     // CalendarPeriodType functionality
     // -------------------------------------------------------------------------
-
     @Override
     public Period getNextPeriod( Period period )
     {
@@ -120,7 +120,7 @@
 
         return new Period( this, startDate, cal.getTime() );
     }
-    
+
     /**
      * Generates monthly Periods for the whole year in which the given Period's
      * startDate exists.
@@ -145,4 +145,11 @@
 
         return months;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        SimpleDateFormat format = new SimpleDateFormat( "yyyyMM" );
+        return format.format( period.getStartDate() );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java	2010-06-14 15:51:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java	2010-12-20 12:43:44 +0000
@@ -114,4 +114,10 @@
 
         period.setEndDate( cal.getTime() );
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        throw new UnsupportedOperationException( "Not supported yet." );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2010-12-20 12:43:44 +0000
@@ -175,6 +175,14 @@
     // -------------------------------------------------------------------------
 
     /**
+     * Returns an ISO8601 formatted string version of the period
+     *
+     * @return the period string
+     */
+    String getIsoDate() {
+        return periodType.getIsoDate(this);
+    }
+    /**
      * Copies the transient properties (name) from the argument Period
      * to this Period.
      * 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2010-11-17 03:17:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2010-12-20 12:43:44 +0000
@@ -198,6 +198,14 @@
         calendar.set( Calendar.HOUR_OF_DAY, 0 );
     }
 
+    /**
+     * Returns an iso8601 formatted string representation of the period
+     *
+     * @param period
+     * @return the period as string
+     */
+    public abstract String getIsoDate(Period period);
+
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -150,4 +150,34 @@
 
         return quarters;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        Calendar cal = createCalendarInstance( period.getStartDate() );
+        int year = cal.get( Calendar.YEAR);
+        int month = cal.get( Calendar.MONTH);
+
+        String periodString = null;
+
+        switch (month) {
+            case Calendar.JANUARY:
+                periodString = year + "Q1";
+                break;
+            case Calendar.APRIL:
+                periodString = year + "Q2";
+                break;
+            case Calendar.JULY:
+                periodString = year + "Q3";
+                break;
+            case Calendar.OCTOBER:
+                periodString = year + "Q1";
+                break;
+            default:
+                throw new RuntimeException("Not a valid quarterly period");
+        }
+
+        return periodString;
+    }
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -150,4 +150,28 @@
 
         return sixMonths;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        Calendar cal = createCalendarInstance( period.getStartDate() );
+        int year = cal.get( Calendar.YEAR);
+        int month = cal.get( Calendar.MONTH);
+
+        String periodString = null;
+
+        switch (month) {
+            case Calendar.JANUARY:
+                periodString = year + "S1";
+                break;
+            case Calendar.JULY:
+                periodString = year + "S2";
+                break;
+            default:
+                throw new RuntimeException("Not a valid six-monthly period");
+        }
+
+        return periodString;
+    }
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SurveyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SurveyPeriodType.java	2010-06-14 15:51:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SurveyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -75,4 +75,10 @@
     {
         return 0;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        throw new UnsupportedOperationException( "Not supported yet." );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -148,4 +148,10 @@
 
         return twoYears;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        throw new UnsupportedOperationException( "Not supported yet." );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -202,4 +202,16 @@
 
         return weeks;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        Calendar cal = createCalendarInstance( period.getStartDate() );
+        int year = cal.get( Calendar.YEAR);
+        int week = cal.get( Calendar.WEEK_OF_YEAR);
+
+        String periodString = year + "W" + week;
+        return periodString;
+    }
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2010-07-18 15:17:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2010-12-20 12:43:44 +0000
@@ -142,4 +142,17 @@
 
         return years;
     }
+
+    @Override
+    public String getIsoDate( Period period )
+    {
+        Calendar cal = createCalendarInstance( period.getStartDate() );
+        int year = cal.get( Calendar.YEAR);
+
+        String periodString = String.valueOf( year );
+
+        return periodString;
+    }
+
+
 }