summaryrefslogtreecommitdiff
path: root/src/Format.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Format.cpp')
-rw-r--r--src/Format.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Format.cpp b/src/Format.cpp
new file mode 100644
index 0000000..71a0e9e
--- /dev/null
+++ b/src/Format.cpp
@@ -0,0 +1,35 @@
+
+#include <time.h>
+#include <string>
+#include "Format.h"
+
+std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
+{
+ struct tm * timeData;
+ char buffer[128];
+
+ timeData = localtime(&unixtime);
+
+ strftime(buffer, 128, dateFormat.c_str(), timeData);
+ return std::string(buffer);
+}
+
+std::string format::UnixtimeToDateMini(time_t unixtime)
+{
+ time_t currentTime = time(NULL);
+ struct tm currentTimeData = *localtime(&currentTime);
+ struct tm timeData = *localtime(&unixtime);
+
+ if(currentTimeData.tm_year != timeData.tm_year)
+ {
+ return UnixtimeToDate(unixtime, "%b %Y");
+ }
+ else if(currentTimeData.tm_mon != timeData.tm_mon || currentTimeData.tm_mday != timeData.tm_mday)
+ {
+ return UnixtimeToDate(unixtime, "%d %B");
+ }
+ else
+ {
+ return UnixtimeToDate(unixtime, "%H:%M:%S");
+ }
+}