DateConverter { public Model getEnglishDate(@IntRange(from = 1970, to = 2090) int nepYY, @IntRange(from = 1, to = 12) int nepMM, @IntRange(from = 1, to = 32) int nepDD) { if (isNepDateInConversionRange(nepYY, nepMM, nepDD)) { int startingEngYear = 1913; int startingEngMonth = 4; int startingEngDay = 13; int startingDayOfWeek = Calendar.SUNDAY; int startingNepYear = 1970; int startingNepMonth = 1; int startingNepDay = 1; Model tempModel = new Model(); int engYY, engMM, engDD; long totalNepDaysCount = 0; for (int i = startingNepYear; i < nepYY; i++) { for (int j = 1; j <= 12; j++) { totalNepDaysCount = totalNepDaysCount + daysInMonthMap.get(i)[j]; } } for (int j = startingNepMonth; j < nepMM; j++) { totalNepDaysCount = totalNepDaysCount + daysInMonthMap.get(nepYY)[j]; } totalNepDaysCount += nepDD - startingNepDay; int[] daysInMonth = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int[] daysInMonthOfLeapYear = new int[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; engYY = startingEngYear; engMM = startingEngMonth; engDD = startingEngDay; int endDayOfMonth; int dayOfWeek = startingDayOfWeek; while (totalNepDaysCount != 0) { if (isEngLeapYear(engYY)) { endDayOfMonth = daysInMonthOfLeapYear[engMM]; } else { endDayOfMonth = daysInMonth[engMM]; } engDD++; dayOfWeek++; if (engDD > endDayOfMonth) { engMM++; engDD = 1; if (engMM > 12) { engYY++; engMM = 1; } } if (dayOfWeek > 7) { dayOfWeek = 1; } totalNepDaysCount--; } tempModel.setDay(engDD); tempModel.setYear(engYY); tempModel.setMonth(engMM - 1); tempModel.setDayOfWeek(dayOfWeek); return tempModel; } else throw new IllegalArgumentException("Out of Range: Date is out of range to Convert"); } DateConverter(); Model getEnglishDate(@IntRange(from = 1970, to = 2090) int nepYY,
                                @IntRange(from = 1, to = 12) int nepMM,
                                @IntRange(from = 1, to = 32) int nepDD); @SuppressWarnings("unused") Calendar getEnglishDate(Model date); Model getNepaliDate(@IntRange(from = 1913 - 2033) int engYY,
                               @IntRange(from = 1, to = 12) int engMM,
                               @IntRange(from = 1, to = 31) int engDD); @SuppressWarnings("unused") Model getNepaliDate(Calendar date); @Contract(pure = true) static int getNepaliMonthString(@IntRange(from = 0, to = 11) int month); int getFirstWeekDayMonth(@IntRange(from = 1970, to = 2090) int yy, @IntRange(from = 1, to = 12) int mm); int noOfDaysInMonth(@IntRange(from = 1970, to = 2090) int yy, @IntRange(from = 1, to = 12) int mm); int getWeekDay(@IntRange(from = 1970, to = 2090) int yy, @IntRange(from = 1, to = 12) int mm, @IntRange(from = 1, to = 32) int dd); Model getTodayNepaliDate(); @SuppressWarnings("unused") static Calendar convertModelToCalendar(Model tempModel); @SuppressWarnings("unused") static Model convertCalendarToModel(Calendar date); static ArrayList<Model> getAllSaturdays();  }
@Test public void getEnglishDate() { Calendar calendar = new GregorianCalendar(2017, 1, 18); Model nepaliDate = dc.getNepaliDate(calendar); assertThat(nepaliDate.getDay(), is(7)); assertThat(nepaliDate.getMonth(), is(10)); assertThat(nepaliDate.getYear(), is(2073)); }