← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15224: expose plusDays, plusWeeks, plusMonths, plusYears, minusDays, minusWeeks, minusMonths, minusYears...

 

------------------------------------------------------------
revno: 15224
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-05-12 09:52:08 +0200
message:
  expose plusDays, plusWeeks, plusMonths, plusYears, minusDays, minusWeeks, minusMonths, minusYears in Calendar (and implementations)
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/impl/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-05-12 07:16:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-05-12 07:52:08 +0000
@@ -251,4 +251,68 @@
      * @see <a href="http://en.wikipedia.org/wiki/Internationalization_and_localization";>http://en.wikipedia.org/wiki/Internationalization_and_localization</a>
      */
     String shortNameOfDay( int day );
+
+    /**
+     * Returns a new dateUnit with specified number of days added
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param days     Days to add
+     * @return dateUnit + days
+     */
+    DateUnit plusDays( DateUnit dateUnit, int days );
+
+    /**
+     * Returns a new dateUnit with specified number of days subtracted
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param days     Days to subtract
+     * @return dateUnit - days
+     */
+    DateUnit minusDays( DateUnit dateUnit, int days );
+
+    /**
+     * Returns a new dateUnit with specified number of weeks added
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param weeks    Weeks to add
+     * @return dateUnit + weeks
+     */
+    DateUnit plusWeeks( DateUnit dateUnit, int weeks );
+
+    /**
+     * Returns a new dateUnit with specified number of weeks subtracted
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param weeks    Weeks to subtract
+     * @return dateUnit - weeks
+     */
+    DateUnit minusWeeks( DateUnit dateUnit, int weeks );
+
+    /**
+     * Returns a new dateUnit with specified number of months added
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param months   Months to add
+     * @return dateUnit + months
+     */
+    DateUnit plusMonths( DateUnit dateUnit, int months );
+
+    /**
+     * Returns a new dateUnit with specified number of months subtracted
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param months   Months to subtract
+     * @return dateUnit - months
+     */
+    DateUnit minusMonths( DateUnit dateUnit, int months );
+
+    /**
+     * Returns a new dateUnit with specified number of years added
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param years    Years to add
+     * @return dateUnit + years
+     */
+    DateUnit plusYears( DateUnit dateUnit, int years );
+
+    /**
+     * Returns a new dateUnit with specified number of years subtracted
+     * @param dateUnit DateUnit representing local year, month, day
+     * @param years    Years to subtract
+     * @return dateUnit - years
+     */
+    DateUnit minusYears( DateUnit dateUnit, int years );
 }

=== 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-05-09 21:24:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-05-12 07:52:08 +0000
@@ -234,4 +234,60 @@
         DateTime dateTime = dateUnit.toDateTime( chronology );
         return dateTime.getDayOfWeek();
     }
+
+    @Override
+    public DateUnit plusDays( DateUnit dateUnit, int days )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.plusDays( days ) );
+    }
+
+    @Override
+    public DateUnit minusDays( DateUnit dateUnit, int days )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.minusDays( days ) );
+    }
+
+    @Override
+    public DateUnit plusWeeks( DateUnit dateUnit, int weeks )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.plusWeeks( weeks ) );
+    }
+
+    @Override
+    public DateUnit minusWeeks( DateUnit dateUnit, int weeks )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.minusWeeks( weeks ) );
+    }
+
+    @Override
+    public DateUnit plusMonths( DateUnit dateUnit, int months )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.plusMonths( months ) );
+    }
+
+    @Override
+    public DateUnit minusMonths( DateUnit dateUnit, int months )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.minusMonths( months ) );
+    }
+
+    @Override
+    public DateUnit plusYears( DateUnit dateUnit, int years )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.plusYears( years ) );
+    }
+
+    @Override
+    public DateUnit minusYears( DateUnit dateUnit, int years )
+    {
+        DateTime dateTime = dateUnit.toDateTime( chronology );
+        return DateUnit.fromDateTime( dateTime.minusYears( years ) );
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-05-09 21:44:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-05-12 07:52:08 +0000
@@ -309,7 +309,8 @@
         return conversionMap.get( year )[0];
     }
 
-    private DateUnit minusYears( DateUnit dateUnit, int years )
+    @Override
+    public DateUnit minusYears( DateUnit dateUnit, int years )
     {
         DateUnit result = new DateUnit( dateUnit.getYear() - years, dateUnit.getMonth(), dateUnit.getDay(), dateUnit.getDayOfWeek() );
         updateDateUnit( result );
@@ -317,7 +318,8 @@
         return result;
     }
 
-    private DateUnit minusMonths( DateUnit dateUnit, int months )
+    @Override
+    public DateUnit minusMonths( DateUnit dateUnit, int months )
     {
         DateUnit result = new DateUnit( dateUnit );
 
@@ -339,12 +341,14 @@
         return result;
     }
 
-    private DateUnit minusWeeks( DateUnit dateUnit, int weeks )
+    @Override
+    public DateUnit minusWeeks( DateUnit dateUnit, int weeks )
     {
         return minusDays( dateUnit, weeks * daysInWeek() );
     }
 
-    private DateUnit minusDays( DateUnit dateUnit, int days )
+    @Override
+    public DateUnit minusDays( DateUnit dateUnit, int days )
     {
         int curYear = dateUnit.getYear();
         int curMonth = dateUnit.getMonth();
@@ -381,7 +385,8 @@
         return new DateUnit( curYear, curMonth, curDay, dayOfWeek );
     }
 
-    private DateUnit plusYears( DateUnit dateUnit, int years )
+    @Override
+    public DateUnit plusYears( DateUnit dateUnit, int years )
     {
         DateUnit result = new DateUnit( dateUnit.getYear() + years, dateUnit.getMonth(), dateUnit.getDay(), dateUnit.getDayOfWeek() );
         updateDateUnit( result );
@@ -389,7 +394,8 @@
         return result;
     }
 
-    private DateUnit plusMonths( DateUnit dateUnit, int months )
+    @Override
+    public DateUnit plusMonths( DateUnit dateUnit, int months )
     {
         DateUnit result = new DateUnit( dateUnit );
 
@@ -411,12 +417,14 @@
         return result;
     }
 
-    private DateUnit plusWeeks( DateUnit dateUnit, int weeks )
+    @Override
+    public DateUnit plusWeeks( DateUnit dateUnit, int weeks )
     {
         return plusDays( dateUnit, weeks * daysInWeek() );
     }
 
-    private DateUnit plusDays( DateUnit dateUnit, int days )
+    @Override
+    public DateUnit plusDays( DateUnit dateUnit, int days )
     {
         int curYear = dateUnit.getYear();
         int curMonth = dateUnit.getMonth();