• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-client-core / #174

pending completion
#174

Pull #921

github-actions

web-flow
Merge 66d3a69a9 into f9f6e7f97
Pull Request #921: Refactor user settings task

18309 of 26768 relevant lines covered (68.4%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.21
opensrp-core/src/main/java/org/smartregister/domain/ReportMonth.java
1
package org.smartregister.domain;
2

3
import org.joda.time.LocalDate;
4
import org.smartregister.util.DateUtil;
5

6
import java.util.Date;
7

8
public class ReportMonth {
1✔
9

10
    public static final int FIRST_REPORT_MONTH_OF_YEAR = 3;
11
    public static final int REPORTING_MONTH_START_DAY = 26;
12
    public static final int REPORTING_MONTH_END_DAY = 25;
13
    private static final int JANUARY = 1;
14
    private static final int DECEMBER = 12;
15

16
    public Date startDateOfReportingYear() {
17
        int reportingYear = reportingYear();
×
18
        return new LocalDate().withDayOfMonth(REPORTING_MONTH_START_DAY)
×
19
                .withMonthOfYear(FIRST_REPORT_MONTH_OF_YEAR).withYear(reportingYear).toDate();
×
20
    }
21

22
    public int reportingYear() {
23
        LocalDate now = DateUtil.today();
×
24
        LocalDate beginningOfReportingYear = DateUtil.today()
×
25
                .withMonthOfYear(FIRST_REPORT_MONTH_OF_YEAR)
×
26
                .withDayOfMonth(REPORTING_MONTH_START_DAY);
×
27
        return now.isBefore(beginningOfReportingYear) ? previousYear(now) : now.getYear();
×
28
    }
29

30
    public LocalDate startDateOfNextReportingMonth(LocalDate date) {
31
        if (date.getDayOfMonth() < REPORTING_MONTH_START_DAY) {
×
32
            return new LocalDate(date.getYear(), date.getMonthOfYear(), REPORTING_MONTH_START_DAY);
×
33
        }
34
        if (date.getMonthOfYear() == DECEMBER) {
×
35
            return new LocalDate(date.plusYears(1).getYear(), JANUARY, REPORTING_MONTH_START_DAY);
×
36
        }
37
        return new LocalDate(date.getYear(), date.plusMonths(1).getMonthOfYear(),
×
38
                REPORTING_MONTH_START_DAY);
39
    }
40

41
    public LocalDate endDateOfReportingMonthGivenStartDate(LocalDate startDate) {
42
        return startDate.plusMonths(1).minusDays(1);
×
43
    }
44

45
    public LocalDate startOfCurrentReportMonth(LocalDate date) {
46
        if (date.getDayOfMonth() >= REPORTING_MONTH_START_DAY) {
1✔
47
            return new LocalDate(date.getYear(), date.getMonthOfYear(), REPORTING_MONTH_START_DAY);
×
48
        }
49
        if (date.getMonthOfYear() == JANUARY) {
1✔
50
            return new LocalDate(previousYear(date), DECEMBER, REPORTING_MONTH_START_DAY);
×
51
        }
52
        return new LocalDate(date.getYear(), previousMonth(date), REPORTING_MONTH_START_DAY);
1✔
53
    }
54

55
    public LocalDate endOfCurrentReportMonth(LocalDate date) {
56
        if (date.getDayOfMonth() > REPORTING_MONTH_END_DAY) {
1✔
57
            if (date.getMonthOfYear() == DECEMBER) {
×
58
                return new LocalDate(nextYear(date), JANUARY, REPORTING_MONTH_END_DAY);
×
59
            } else {
60
                return new LocalDate(date.getYear(), nextMonth(date), REPORTING_MONTH_END_DAY);
×
61
            }
62
        } else {
63
            return new LocalDate(date.getYear(), date.getMonthOfYear(), REPORTING_MONTH_END_DAY);
1✔
64
        }
65
    }
66

67
    public boolean isDateWithinCurrentReportMonth(LocalDate lastReportedDate) {
68
        return !(lastReportedDate.isBefore(startOfCurrentReportMonth(DateUtil.today()))
×
69
                || lastReportedDate.isAfter(endOfCurrentReportMonth(DateUtil.today())));
×
70
    }
71

72
    private int previousMonth(LocalDate today) {
73
        return today.getMonthOfYear() - 1;
1✔
74
    }
75

76
    private int nextMonth(LocalDate today) {
77
        return today.getMonthOfYear() + 1;
×
78
    }
79

80
    private int previousYear(LocalDate today) {
81
        return today.getYear() - 1;
×
82
    }
83

84
    private int nextYear(LocalDate today) {
85
        return today.getYear() + 1;
×
86
    }
87

88
    public int reportingMonth(LocalDate date) {
89
        return endOfCurrentReportMonth(date).getMonthOfYear();
×
90
    }
91

92
    public int reportingYear(LocalDate date) {
93
        return endOfCurrentReportMonth(date).getYear();
×
94
    }
95
}
96

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc