[Common] Add Date Time Class

This commit is contained in:
zilmar 2016-02-24 17:59:29 +11:00
parent 2f7894c6e2
commit 8d6e71fa0a
4 changed files with 59 additions and 0 deletions

View File

@ -46,6 +46,7 @@
</ClCompile>
<ClCompile Include="StdString.cpp" />
<ClCompile Include="SyncEvent.cpp" />
<ClCompile Include="DateTimeClass.cpp" />
<ClCompile Include="Trace.cpp" />
<ClCompile Include="Util.cpp" />
</ItemGroup>
@ -64,6 +65,7 @@
<ClInclude Include="StdString.h" />
<ClInclude Include="stdtypes.h" />
<ClInclude Include="SyncEvent.h" />
<ClInclude Include="DateTimeClass.h" />
<ClInclude Include="Trace.h" />
<ClInclude Include="TraceModulesCommon.h" />
<ClInclude Include="Util.h" />

View File

@ -53,6 +53,9 @@
<ClCompile Include="MemoryManagement.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DateTimeClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
@ -106,5 +109,8 @@
<ClInclude Include="MemoryManagement.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DateTimeClass.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,36 @@
#include "stdafx.h"
#include "DateTimeClass.h"
#include <sys/timeb.h>
#include <time.h>
CDateTime::CDateTime()
{
m_time = 0;
}
CDateTime & CDateTime::SetToNow(void)
{
struct timeb now;
(void)::ftime(&now);
m_time = (now.time * 1000l) + now.millitm;
return *this;
}
std::string CDateTime::Format (const char * format)
{
char buffer[100];
time_t TimeValue = m_time / 1000l;
strftime(buffer, sizeof(buffer), format, localtime(&TimeValue));
return std::string(buffer);
}
double CDateTime::DiffernceMilliseconds (const CDateTime & compare)
{
double diff = (double)(m_time - compare.m_time);
return diff / 1000.0;
}
uint64_t CDateTime::Value ( void )
{
return m_time;
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "stdtypes.h"
class CDateTime
{
public:
CDateTime();
CDateTime & SetToNow (void);
std::string Format (const char * format);
double DiffernceMilliseconds (const CDateTime & compare);
uint64_t Value ( void );
private:
uint64_t m_time;
};