package org.dhis2.mobile.utils.date.filters;


import org.dhis2.mobile.utils.date.PeriodFilter;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;

public class FinJulyYearPeriodFilter extends PeriodFilter {
    public FinJulyYearPeriodFilter(DateTime startDate, DateTime endDate) {
        super(fixStartDate(startDate), fixEndDate(endDate));
    }

    private static DateTime fixStartDate(DateTime startDate) {
        if (startDate == null) {
            return null;
        }
        int month = startDate.getMonthOfYear();
        if (month < 6) {
            return startDate.withMonthOfYear(DateTimeConstants.JUNE).withDayOfMonth(30).withYear(
                    startDate.getYear() - 1);
        } else {
            return startDate.withMonthOfYear(DateTimeConstants.JUNE).withDayOfMonth(30);
        }
    }

    private static DateTime fixEndDate(DateTime endDate) {
        if (endDate == null) {
            return null;
        }
        int month = endDate.getMonthOfYear();
        if (month <= 6) {
            return endDate.withMonthOfYear(DateTimeConstants.JULY).withDayOfMonth(1);
        } else {
            return endDate.withMonthOfYear(DateTimeConstants.JULY).withDayOfMonth(1).withYear(endDate.getYear()+1);
        }
    }

}

@@ -625,34 +625,34 @@
 TimeConstants.JU
-NE
+LY
 ).withDayOfMonth
@@ -652,18 +652,17 @@
 OfMonth(
-30
+1
 ).withYe
@@ -797,10 +797,10 @@
 s.JU
-NE
+LY
 ).wi
@@ -816,10 +816,9 @@
 nth(
-30
+1
 );%0A 
@@ -1085,34 +1085,34 @@
 TimeConstants.JU
-LY
+NE
 ).withDayOfMonth
@@ -1104,33 +1104,34 @@
 .withDayOfMonth(
-1
+30
 );%0A        %7D els
@@ -1189,34 +1189,34 @@
 TimeConstants.JU
-LY
+NE
 ).withDayOfMonth
@@ -1208,33 +1208,34 @@
 .withDayOfMonth(
-1
+30
 ).withYear(endDa
@@ -1268,10 +1268,1006 @@
 %0A    %7D%0A%0A
+    @Override%0A    public boolean apply() %7B%0A        if ((startDate == null && endDate == null) %7C%7C selectedDate == null) %7B%0A            return false;%0A        %7D%0A%0A        if (startDate != null && endDate != null) %7B%0A            // return true, if criteria is not between two dates%0A            // return startDate.isBefore(selectedDate) %7C%7C endDate.isAfter(selectedDate);%0A            return !((selectedDate.isAfter(startDate) %7C%7C selectedDate.isEqual(startDate))%0A                    && (selectedDate.isBefore(endDate) %7C%7C selectedDate.isEqual(endDate)));%0A        %7D%0A%0A        if (startDate != null) %7B%0A            // return true, if criteria is before startDate%0A            // return startDate.isBefore(selectedDate);%0A            return !(selectedDate.isAfter(startDate) %7C%7C selectedDate.isEqual(startDate));%0A        %7D%0A%0A        // return true, if criteria is after endDate%0A        // return endDate.isAfter(selectedDate);%0A        return !(selectedDate.isBefore(endDate) %7C%7C selectedDate.equals(endDate));%0A    %7D%0A
 %7D%0A

fix fin july period filter bug