Fichier Date.h
/**
*
* \file Date.h
*
* \authors M. Laporte
*
* \date 24/05/2018
*
* \version V1.0
*
* \brief Declaration de la classe Date
*
**/
#ifndef __DATE_H__
#define __DATE_H__
#include <ctime> // struct tm
namespace std
{
class Date : public tm
{
public :
Date (void);
unsigned getYear (void) const;
unsigned getMonth (void) const;
unsigned getDay (void) const;
unsigned getHour (void) const;
unsigned getMinute (void) const;
unsigned getSecond (void) const;
}; // Date
} // std
#endif /* __DATE_H__ */
Fichier Date.cpp
/**
*
* \file Date.cpp
*
* \authors M. Laporte
*
* \date 24/05/2018
*
* \version V1.0
*
* \brief Definitions de la classe Date
*
**/
#include "date.h"
std::Date::Date (void)
{
time_t whatTime;
time (& whatTime);
tm local;
local = * localtime (&whatTime);
tm_year = local.tm_year;
tm_mon = local.tm_mon;
tm_mday = local.tm_mday;
tm_hour = local.tm_hour;
tm_min = local.tm_min;
tm_sec = local.tm_sec;
//*this = * ((Date *) localtime (&whatTime));
tm_year += 1900;
tm_mon += 1;
}
unsigned std::Date::getYear (void) const { return tm_year; }
unsigned std::Date::getMonth (void) const { return tm_mon; }
unsigned std::Date::getDay (void) const { return tm_mday; }
unsigned std::Date::getHour (void) const { return tm_hour; }
unsigned std::Date::getMinute (void) const { return tm_min; }
unsigned std::Date::getSecond (void) const { return tm_sec; }