← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14976: support for generating iso intervals for year, and year-month

 

------------------------------------------------------------
revno: 14976
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-25 13:18:35 +0545
message:
  support for generating iso intervals for year, and year-month
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.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/calendar/Calendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-04-25 06:29:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-04-25 07:33:35 +0000
@@ -41,6 +41,10 @@
 
     DateUnit fromIso( DateUnit dateUnit );
 
+    DateInterval toIsoInterval( int year );
+
+    DateInterval toIsoInterval( int year, int month );
+
     DateUnit today();
 
     int monthsInYear();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-04-25 06:37:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-04-25 07:33:35 +0000
@@ -61,6 +61,30 @@
     }
 
     @Override
+    public DateInterval toIsoInterval( int year )
+    {
+        DateUnit from = new DateUnit( year, 1, 1 );
+        DateUnit to = new DateUnit( year, monthsInYear(), daysInMonth( year, monthsInYear() ) );
+
+        from.setDayOfWeek( isoWeekday( from ) );
+        to.setDayOfWeek( isoWeekday( to ) );
+
+        return new DateInterval( from, to );
+    }
+
+    @Override
+    public DateInterval toIsoInterval( int year, int month )
+    {
+        DateUnit from = new DateUnit( year, month, 1 );
+        DateUnit to = new DateUnit( year, month, daysInMonth( year, month ) );
+
+        from.setDayOfWeek( isoWeekday( from ) );
+        to.setDayOfWeek( isoWeekday( to ) );
+
+        return new DateInterval( from, to );
+    }
+
+    @Override
     public int monthsInYear()
     {
         DateTime dateTime = new DateTime( 1, 1, 1, 0, 0, chronology );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java	2014-04-25 06:29:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java	2014-04-25 07:33:35 +0000
@@ -121,6 +121,30 @@
     }
 
     @Override
+    public DateInterval toIsoInterval( int year )
+    {
+        DateUnit from = new DateUnit( year, 1, 1 );
+        DateUnit to = new DateUnit( year, monthsInYear(), daysInMonth( year, monthsInYear() ) );
+
+        from = toIso( from );
+        to = toIso( to );
+
+        return new DateInterval( from, to );
+    }
+
+    @Override
+    public DateInterval toIsoInterval( int year, int month )
+    {
+        DateUnit from = new DateUnit( year, month, 1 );
+        DateUnit to = new DateUnit( year, month, daysInMonth( year, month ) );
+
+        from = toIso( from );
+        to = toIso( to );
+
+        return new DateInterval( from, to );
+    }
+
+    @Override
     public int daysInYear( int year )
     {
         return getYearTotal( year );