// Author: Juan Carlos De Abreu (jcabreur@gmail.com)

#include "Calendar.h"

BEGIN_TEG_NAMESPACE();

// Standard Constructor
Calendar::Calendar() {
  // Get the local date and time of the machine
  time_t szClock;
  time(&szClock);
  m_time = localtime(&szClock);
}

Calendar::~Calendar() {}

// Method to get the day of the weak 
std::tstring Calendar::GetDayOfWeak() {
  switch(m_time->tm_wday) {
    case 0: return _T("Sunday"); break;
    case 1: return _T("Monday"); break;
    case 2: return _T("Tuesday"); break;
    case 3: return _T("Wednesday"); break;
    case 4: return _T("Thursday"); break;
    case 5: return _T("Friday"); break;
    case 6: return _T("Saturday"); break;
    default: return _T("DayOfWeak_Error"); break;
  }
}	

// Method to get the day of the month
std::tstring Calendar::GetDayOfMonth() {
  std::tstring day = toString(m_time->tm_mday);
  switch(m_time->tm_mday % 10) {
    case 1:	return day + _T("st");
    case 2:	return day + _T("nd");
    case 3:	return day + _T("rd");
    default:return day + _T("th");
  }
}

// Method to get the month
std::tstring Calendar::GetMonth() {
  switch(m_time->tm_mon) {
    case 0: return _T("January"); break;
    case 1: return _T("February"); break;
    case 2: return _T("March"); break;
    case 3: return _T("April"); break;
    case 4: return _T("May"); break;
    case 5: return _T("June"); break;
    case 6: return _T("July"); break;
    case 7: return _T("August"); break;
    case 8: return _T("September"); break;
    case 9: return _T("October"); break;
    case 10: return _T("November"); break;
    case 11: return _T("December"); break;
    default: return _T("Month_Error"); break;
  }
}

// Method to get the year
std::tstring Calendar::GetYear() {
  return toString(m_time->tm_year + 1900);	
}

// Method to get the current time
std::tstring Calendar::GetCurrentTime_() {
  std::tstring currentTime;

  // Print the time in the format hh:mm:ss
  sprintf(currentTime, "%02d:%02d:%02d", m_time->tm_hour, m_time->tm_min, m_time->tm_sec);
	
  return currentTime;
}

// Method to get the current date
std::tstring Calendar::GetCurrentDate() {
  return GetDayOfWeak() + _T(" ") + GetDayOfMonth() + _T(" ") + GetMonth() + _T(" ") + GetYear();
}

END_TEG_NAMESPACE();
