@@ -0,0 +1,2335 @@
+package me.pagarme.util;%0A%0Aimport java.net.URL;%0Aimport java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Locale;%0Aimport java.util.Scanner;%0Aimport org.json.JSONArray;%0Aimport org.json.JSONObject;%0Aimport org.joda.time.DateTime;%0A%0Apublic class PagarmeCalendar %7B%0A    private static final String HOLIDAY_CALENDAR_PATH = %22https://raw.githubusercontent.com/pagarme/business-calendar/master/data/brazil/%22;%0A%0A    private static JSONArray getPagarmeOfficialHolidayCalendar(Integer year) throws Exception %7B%0A        URL holidayCalendarURL = new URL(HOLIDAY_CALENDAR_PATH + year + %22.json%22);%0A        Scanner scanner = new Scanner(holidayCalendarURL.openStream());%0A        String responseJSON = scanner.useDelimiter(%22%5C%5CZ%22).next();%0A        scanner.close();%0A        JSONObject calendarJSON = new JSONObject(responseJSON);%0A        JSONArray holidayCalendarAsJSONArray = (JSONArray) calendarJSON.getJSONArray(%22calendar%22);%0A%0A        return holidayCalendarAsJSONArray;%0A    %7D%0A%0A    private static String%5B%5D getHolidays(Integer year) throws Exception %7B%0A        JSONArray holidayCalendarAsJSONArray = getPagarmeOfficialHolidayCalendar(year);%0A        String%5B%5D holidays = new String%5BholidayCalendarAsJSONArray.length()%5D;%0A        for (int i = 0; i %3C holidayCalendarAsJSONArray.length(); i++) %7B%0A            holidays%5Bi%5D = holidayCalendarAsJSONArray.getJSONObject(i).get(%22date%22).toString();%0A        %7D%0A%0A        return holidays;%0A    %7D%0A%0A    public static DateTime getValidWeekday() throws Exception %7B%0A        DateTime weekday = new DateTime().plusDays(7);%0A%0A        while ((isWeekend(weekday) == true %7C%7C isHoliday(weekday) == true))%7B%0A            weekday = weekday.plusDays(2);%0A        %7D%0A%0A        return weekday;%0A    %7D%0A%0A    public static Boolean isWeekend(DateTime weekday) throws Exception %7B%0A        DateFormat dayName = new SimpleDateFormat(%22EEE%22, Locale.ENGLISH);%0A        return (dayName.format(weekday.toDate()).equals(%22Sun%22) %7C%7C dayName.format(weekday.toDate()).equals(%22Sat%22));%0A    %7D%0A%0A    public static Boolean isHoliday(DateTime weekday) throws Exception %7B%0A        DateFormat yearMonthDay = new SimpleDateFormat(%22yyyy-MM-dd%22);%0A        for (String holiday : getHolidays(weekday.getYear())) %7B%0A            if (yearMonthDay.format(weekday.toDate()).equals(holiday)) %7B%0A                return true;%0A            %7D%0A        %7D%0A%0A        return false;%0A    %7D%0A%7D%0A

add pagarme calendar util to validate weekdays, excluding weekends and holidays