// Local header files
#include "Date.h"
#include "calcDays.h"

int calcDays(Date &date1, Date &date2) { // Calculate the difference in days between dateExposed and dateSecondDose

    int baseNumDays = getNumDays(1, 1, 2021); // Store the number of days from base date 1/1/2021

    int date1NumDays = getNumDays(date1.getMonth(), date1.getDay(), date1.getYear()); // Store the number of days from dateExposed
    int daysDiff1 = date1NumDays - baseNumDays; // Calculate the difference between dateExposed and base date

    int date2NumDays = getNumDays(date2.getMonth(), date2.getDay(), date2.getYear()); // Store the number of days from dateSecondDose
    int daysDiff2 = date2NumDays - baseNumDays; // Calculate the difference between dateSecondDose and base date

    int numDaysDiff = daysDiff1 - daysDiff2; // Calculate the difference between the number of days from dateExposed and the number of days from dateSecondDose

    return numDaysDiff; // Return calculated difference

}

int getNumDays(int month, int day, int year) { // Calculate number of days based on given day, month, and year

    int numDays = 0; // Initialize numDays as zero to prevent errors

    if (year == 2022) { // If year is 2022
    // This works because the program's scope is limited to 2021 and 2022
        numDays = numDays + 365;
    }

    // Series of if conditions that handle the number of days for each month
    if (month > 1) {
        numDays = numDays + 31;
    }
    if (month > 2) {
        numDays = numDays + 28;
    }
    if (month > 3) {
        numDays = numDays + 31;
    }
    if (month > 4) {
        numDays = numDays + 30;
    }
    if (month > 5) {
        numDays = numDays + 31;
    }
    if (month > 6) {
        numDays = numDays + 30;
    }
    if (month > 7) {
        numDays = numDays + 31;
    }
    if (month > 8) {
        numDays = numDays + 31;
    }
    if (month > 9) {
        numDays = numDays + 30;
    }
    if (month > 10) {
        numDays = numDays + 31;
    }
    if (month > 11) {
        numDays = numDays + 30;
    }

    numDays = numDays + day; // Add on the specified number of days

    return numDays; // Return calculated days

}