temp

dateTime.hpp

Committer:
BenRJG
Date:
2018-12-06
Revision:
0:2a4af0cb6e8d

File content as of revision 0:2a4af0cb6e8d:

#ifndef _dateTime_HPP
#define _dateTime_HPP
    #include "mbed.h"
    #include "General.hpp"
    
    class dateTime{
        public:
            dateTime()
						{
							getSystemTime();
							time_t check = -1;
							if(mktime(&_currentTime_struct) == check)
							{
								_currentTime_struct.tm_year = 70;
								_currentTime_struct.tm_mon = 0;
								_currentTime_struct.tm_mday = 1;
								_currentTime_struct.tm_hour = 0;
								_currentTime_struct.tm_min = 0;
								_currentTime_struct.tm_sec = 0;
								printf("THIS HAS BEEN RUN TOO\n\r");
							}
							
							printf("THIS HAS BEEN RUN %d\n\r",check);
						}
            
            
						void updateStruct()
						{	
							time_t _newTime_time = mktime(&_newTime_struct);
							_newTime_struct = *localtime(&_newTime_time);
							if(_newTime_struct.tm_year == 0)
							{
									_newTime_struct = _currentTime_struct;
							}
							_currentTime_struct = _newTime_struct;
						}
						
						void addYear (INT_32 years  =1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_year = _currentTime_struct.tm_year + years;
							updateStruct();
						}
						
						void addMonth(S_BYTE months =1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_mon = _currentTime_struct.tm_mon + months;
							updateStruct();
						}
            void addDay	 (S_BYTE days   =1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_mday = _currentTime_struct.tm_mday + days;
							updateStruct();
						}
            void addHour (S_BYTE hours  =1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_hour = _currentTime_struct.tm_hour + hours;
							updateStruct();
						}
            void addMin  (S_BYTE minutes=1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_min = _currentTime_struct.tm_min + minutes;
							updateStruct();
						}
            void addSec  (S_BYTE seconds=1){
							_newTime_struct = _currentTime_struct;
							_newTime_struct.tm_sec = _currentTime_struct.tm_sec + seconds;
							updateStruct();
						}
						
            void setSystemTime(){set_time(mktime(&_currentTime_struct));}
            char* getSystemTime(){time_t rawTime; time(&rawTime); _currentTime_struct = *localtime(&rawTime); return getTime();}
            
            char* getTime() {sprintf(dateTimeStr,"%02d/%02d/%4d %02d:%02d:%02d",getDay(),getMonth(),getYear(),getHour(),getMin(),getSec()); return dateTimeStr;}
            //char* getTime() {updateTime(); sprintf(dateTimeStr, "Hello world %d:)",42);return dateTimeStr;};
            
            signed INT_32 getYear() {return _currentTime_struct.tm_year + 1900;}
            BYTE getMonth()  {return _currentTime_struct.tm_mon + 1;    }
            BYTE getDay()    {return _currentTime_struct.tm_mday;       }
            BYTE getHour()   {return _currentTime_struct.tm_hour;       }
            BYTE getMin()    {return _currentTime_struct.tm_min;        }
            BYTE getSec()    {return _currentTime_struct.tm_sec;        }
        private:
            //time_t _currentTime_time;
            struct tm _currentTime_struct;
						struct tm _newTime_struct;
            char dateTimeStr[20];
            //01/09/
    };
#endif