From 8d6e71fa0a0c69e7122bd8984ef9d83b183bab4e Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 24 Feb 2016 17:59:29 +1100 Subject: [PATCH] [Common] Add Date Time Class --- Source/Common/Common.vcxproj | 2 ++ Source/Common/Common.vcxproj.filters | 6 +++++ Source/Common/DateTimeClass.cpp | 36 ++++++++++++++++++++++++++++ Source/Common/DateTimeClass.h | 15 ++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 Source/Common/DateTimeClass.cpp create mode 100644 Source/Common/DateTimeClass.h diff --git a/Source/Common/Common.vcxproj b/Source/Common/Common.vcxproj index a6b548f6e..0257fe342 100644 --- a/Source/Common/Common.vcxproj +++ b/Source/Common/Common.vcxproj @@ -46,6 +46,7 @@ + @@ -64,6 +65,7 @@ + diff --git a/Source/Common/Common.vcxproj.filters b/Source/Common/Common.vcxproj.filters index 7367aeb86..bd67d3ab2 100644 --- a/Source/Common/Common.vcxproj.filters +++ b/Source/Common/Common.vcxproj.filters @@ -53,6 +53,9 @@ Source Files + + Source Files + @@ -106,5 +109,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Source/Common/DateTimeClass.cpp b/Source/Common/DateTimeClass.cpp new file mode 100644 index 000000000..517a068b3 --- /dev/null +++ b/Source/Common/DateTimeClass.cpp @@ -0,0 +1,36 @@ +#include "stdafx.h" +#include "DateTimeClass.h" +#include +#include + +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; +} diff --git a/Source/Common/DateTimeClass.h b/Source/Common/DateTimeClass.h new file mode 100644 index 000000000..bb3e54c63 --- /dev/null +++ b/Source/Common/DateTimeClass.h @@ -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; +}; \ No newline at end of file