class ProjectionRepositoryImpl implements ProjectionRepository, Constants {

    public int getWeekNoByDate(LocalDate date) {
        LocalDate lastDayInPreviousQuarter = null;
        int quarter = date.get(IsoFields.QUARTER_OF_YEAR);
        int weekNumber;
        if (quarter > 1) {
            LocalDate previousQuarter = LocalDate.now().minus(1, IsoFields.QUARTER_YEARS);
            // get last day in previous quarter
            long lastDayOfQuarter = IsoFields.DAY_OF_QUARTER.rangeRefinedBy(previousQuarter).getMaximum();
            // get the date corresponding to the last day of quarter
            lastDayInPreviousQuarter = previousQuarter.with(IsoFields.DAY_OF_QUARTER, lastDayOfQuarter);
        }
        WeekFields weekFields = WeekFields.of(Locale.getDefault());
        if (null != lastDayInPreviousQuarter) {
            weekNumber = ((date.get(weekFields.weekOfWeekBasedYear())) - (lastDayInPreviousQuarter.get(weekFields
                    .weekOfWeekBasedYear())));
        } else {
            weekNumber = date.get(weekFields.weekOfWeekBasedYear());
        }
        return weekNumber;
    }

}