From 25f3d40511815fd8c3b257724468f8f563d52396 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Thu, 15 Dec 2016 13:38:13 +0100 Subject: [PATCH] Added function format_date which is format_full_time without time --- src/timefunc.cpp | 12 ++++++++++++ src/timefunc.hxx | 1 + 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/timefunc.cpp b/src/timefunc.cpp index 05aea1a..245c95e 100644 --- a/src/timefunc.cpp +++ b/src/timefunc.cpp @@ -140,6 +140,18 @@ string format_full_time(time_t seconds) return string(buf); } +string format_date(time_t seconds) +{ + char buf[50]; + memset (buf, 0, 50); + struct tm ta; + if (localtime_r((time_t *)&seconds, &ta) == NULL) + memset (&ta, 0, sizeof(struct tm)); + + strftime (buf, 49, "%d.%m.%Y", &ta); + return string(buf); +} + void seconds_to_hour_minute(int seconds, int *hour, int *minute) { if (hour != NULL) { diff --git a/src/timefunc.hxx b/src/timefunc.hxx index 96530b4..18b0314 100644 --- a/src/timefunc.hxx +++ b/src/timefunc.hxx @@ -37,6 +37,7 @@ time_t date_to_seconds(const std::string &date); std::string make_nice_time(int seconds); std::string format_full_time(time_t seconds); +std::string format_date(time_t seconds); void seconds_to_hour_minute(int seconds, int *hour, int *minute); void split_daysec(int daysec, int *outhours=NULL, int *outminutes=NULL, int *outseconds=NULL); std::string output_hour_minute(int hour, int minute, bool h_for_00=true, int seconds=0); -- 1.7.1