#include "Date.h"
#include <ctime>
#include <cstdlib>
#include <sys/time.h>
#include <string>

CData::CData()
{
	time_t t=time(0);
	tm today;
	localtime_r(&t, &today);
	m_uDia = today.tm_mday;
	m_uMes = today.tm_mon + 1;
	m_uAno = today.tm_year + 1900;
}
CData::CData(unsigned d, unsigned m, unsigned a)
{
	m_uDia = d;
	m_uMes = m;
	m_uAno = a;
}
CData::~CData()
{
}
unsigned CData::GetAno()const
{
	return m_uAno;
}

// std::string CData::datatos(unsigned nDigitos, unsigned mec)const
// {
// 	char* temp = new char[nDigitos+1];
// 
// 	ultoa( mec,temp, nDigitos+1, 10);
// 
// 	std::string stringres = temp;
// 
// 	delete []temp;
// 
// 	return stringres;
// }

std::string CData::GetData()const
{
	char buffer[30];
	struct timeval tv;

	time_t curtime;

	gettimeofday(&tv, NULL); 
	curtime=tv.tv_sec;

	strftime(buffer,30,"%d-%m-%Y_%T",localtime(&curtime));
	printf("%s\n",buffer);

// // With microseconds
//   strftime(buffer,30,"%d-%m-%Y_%T.",localtime(&curtime));
//   printf("%s%ld\n",buffer,tv.tv_usec);

	return EXIT_SUCCESS;
}
