diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 12:40:39 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 12:40:39 (GMT) |
| commit | 268795eec167a5fdeadef86dabbedac258e5b20a (patch) | |
| tree | b0c2e8c06ba8454c6191bd87066cb7bb19a6fbe2 /src/Format.cpp | |
| parent | ab8466e9908d3982d498b63197bb80ffb489f3c1 (diff) | |
| download | powder-268795eec167a5fdeadef86dabbedac258e5b20a.zip powder-268795eec167a5fdeadef86dabbedac258e5b20a.tar.gz | |
Add date to Preview View, fixes issue #64
Diffstat (limited to 'src/Format.cpp')
| -rw-r--r-- | src/Format.cpp | 35 |
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(¤tTime); + 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"); + } +} |
