summaryrefslogtreecommitdiff
path: root/louloulibs/utils
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-08-31 01:17:45 +0200
committerlouiz’ <louiz@louiz.org>2016-08-31 01:17:45 +0200
commit2a4905df0153c47656555a21f3d57bbad6f3ffe1 (patch)
treeb2b0608e1a809056c580b1bd4ca9531a11b42c6d /louloulibs/utils
parent9727f4cf00e85e90f89c9b5443ec035c44d4c3f6 (diff)
downloadbiboumi-2a4905df0153c47656555a21f3d57bbad6f3ffe1.tar.gz
biboumi-2a4905df0153c47656555a21f3d57bbad6f3ffe1.tar.bz2
biboumi-2a4905df0153c47656555a21f3d57bbad6f3ffe1.tar.xz
biboumi-2a4905df0153c47656555a21f3d57bbad6f3ffe1.zip
Fix to_string(time_t) and write a unit test for it
Diffstat (limited to 'louloulibs/utils')
-rw-r--r--louloulibs/utils/time.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp
index e23def4..b85d764 100644
--- a/louloulibs/utils/time.cpp
+++ b/louloulibs/utils/time.cpp
@@ -4,9 +4,10 @@ namespace utils
{
std::string to_string(const std::time_t& timestamp)
{
- constexpr std::size_t stamp_size = 20;
- char date_buf[stamp_size];
- std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(&timestamp));
- return {std::begin(date_buf), std::end(date_buf)};
+ constexpr std::size_t stamp_size = 21;
+ char date_buf[stamp_size];
+ if (std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(&timestamp)) != stamp_size - 1)
+ return "";
+ return {std::begin(date_buf), std::end(date_buf) - 1};
}
} \ No newline at end of file