------------------------------------------------------------ revno: 15209 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Fri 2014-05-09 23:44:26 +0200 message: logic for calculating weekly periods for nepali calendar modified: 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/impl/NepaliCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2014-05-09 21:24:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2014-05-09 21:44:26 +0000 @@ -163,7 +163,25 @@ private DateInterval toWeekIsoInterval( DateUnit dateUnit, int offset, int length ) { - return null; + DateUnit from = new DateUnit( dateUnit ); + + if ( offset > 0 ) + { + from = plusWeeks( from, offset ); + } + else if ( offset < 0 ) + { + from = minusWeeks( from, -offset ); + } + + DateUnit to = new DateUnit( from ); + to = plusWeeks( to, length ); + to = minusDays( to, 1 ); + + from = toIso( from ); + to = toIso( to ); + + return new DateInterval( from, to, DateIntervalType.ISO8601_WEEK ); } private DateInterval toDayIsoInterval( DateUnit dateUnit, int offset, int length ) @@ -321,6 +339,11 @@ return result; } + private DateUnit minusWeeks( DateUnit dateUnit, int weeks ) + { + return minusDays( dateUnit, weeks * daysInWeek() ); + } + private DateUnit minusDays( DateUnit dateUnit, int days ) { int curYear = dateUnit.getYear(); @@ -388,6 +411,11 @@ return result; } + private DateUnit plusWeeks( DateUnit dateUnit, int weeks ) + { + return plusDays( dateUnit, weeks * daysInWeek() ); + } + private DateUnit plusDays( DateUnit dateUnit, int days ) { int curYear = dateUnit.getYear();
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp