content: package com.example.app_login.doctor.doctor.schedule;
  
  import android.os.Build;
  import android.support.annotation.RequiresApi;
  
  import java.time.DayOfWeek;
  import java.time.LocalDate;
  import java.time.YearMonth;
  import java.time.format.DateTimeFormatter;
  import java.util.ArrayList;
  
  public class CalenderUtlis {
  
      public static LocalDate selectedDate;
  
  
      @RequiresApi(api = Build.VERSION_CODES.O)
      public static String monthYearFromDate(LocalDate date)
      {
          DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM yyyy");
          return date.format(formatter);
      }
  
      @RequiresApi(api = Build.VERSION_CODES.O)
      public static String monthDayFromDate(LocalDate date)
      {
          DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d");
          return date.format(formatter);
      }
  
  
      @RequiresApi(api = Build.VERSION_CODES.O)
      public static ArrayList<LocalDate> daysInMonthArray(LocalDate date) {
          ArrayList<LocalDate> daysInMonthArray = new ArrayList<>();
          YearMonth yearMonth = YearMonth.from(date);
  
          int daysInMonth = yearMonth.lengthOfMonth();
  
          LocalDate firstOfMonth = CalenderUtlis.selectedDate.withDayOfMonth(1);
          int dayOfWeek = firstOfMonth.getDayOfWeek().getValue();
  
          for(int i = 1; i <= 42; i++)
          {
              if(i <= dayOfWeek || i > daysInMonth + dayOfWeek)
                  daysInMonthArray.add(null);
              else
                  daysInMonthArray.add(LocalDate.of(selectedDate.getYear(),selectedDate.getMonth(),i - dayOfWeek));
          }
          return  daysInMonthArray;
  
      }
  
  
  
  
      @RequiresApi(api = Build.VERSION_CODES.O)
      public static ArrayList<LocalDate> daysInWeekArray(LocalDate selectedDate) {
  
  
          ArrayList<LocalDate> days = new ArrayList<>();
          LocalDate current = sundayForDate(selectedDate);
          LocalDate endDate = current.plusWeeks(1);
  
          while (current.isBefore(endDate))
          {
              days.add(current);
              current=current.plusDays(1);
  
          }
  
          return days;
      }
  
  
  
  
  
      @RequiresApi(api = Build.VERSION_CODES.O)
      private static LocalDate sundayForDate(LocalDate current) {
  
          LocalDate oneWeekAgo = current.minusWeeks(1);
  
          while (current.isAfter(oneWeekAgo))
          {
              if(current.getDayOfWeek() == DayOfWeek.SUNDAY)
                  return current;
  
              current = current.minusDays(1);
          }
  
          return null;
  
      }
  
  
  
  
  
  }
  