#include "CivDate.h"
#include <time.h> 
#include <iostream>
using namespace std;


CivDate::CivDate()
{
    time_t rawtime;
    struct tm* timeinfo;
    char s[100];
    time(&rawtime);

    timeinfo = localtime(&rawtime);
    time_t tick = mktime(timeinfo);
    year = 1900 + timeinfo->tm_year;
    month =1+ timeinfo->tm_mon;
    day = timeinfo->tm_mday;  
}

void CivDate::setDate(int year, int month, int day)
{
    this->year = year;
    this->month = month;
    this->day = day;
}

//add one day
void CivDate::addDate()
{
    if (('y' == flagleap) && (day == YearL[month - 1]))
    {
        day = 1;
        month += 1;
    }
    else if (day == YearNL[month - 1]) 
    {
        day = 1;
        month += 1;
    }
    else
    {
        day += 1;
    }
}
//get the date
std::string  CivDate::getDate()
{

    std::string date;
    date.append(std::to_string(year));
    date.append("-");
    date.append(std::to_string(month));
    date.append("-");
    date.append(std::to_string(day));

    return date;  
}
