diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/renderer/debug_bucket.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/util/chrono.cpp | 35 | ||||
-rw-r--r-- | src/mbgl/util/time.cpp | 30 | ||||
-rw-r--r-- | src/parsedate/parsedate.c (renamed from src/mbgl/util/parsedate.c) | 2 | ||||
-rw-r--r-- | src/parsedate/parsedate.h | 38 |
5 files changed, 76 insertions, 34 deletions
diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index a6663b35c3..2d0590c56b 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -1,7 +1,6 @@ #include <mbgl/renderer/debug_bucket.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/shader/plain_shader.hpp> -#include <mbgl/util/time.hpp> #include <mbgl/platform/gl.hpp> @@ -23,10 +22,10 @@ DebugBucket::DebugBucket(const TileID id, const TileData::State state_, optional } if (debugMode & MapDebugOptions::Timestamps && modified && expires) { - const std::string modifiedText = "modified: " + util::iso8601(SystemClock::to_time_t(*modified)); + const std::string modifiedText = "modified: " + util::iso8601(*modified); fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5); - const std::string expiresText = "expires: " + util::iso8601(SystemClock::to_time_t(*expires)); + const std::string expiresText = "expires: " + util::iso8601(*expires); fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5); } } diff --git a/src/mbgl/util/chrono.cpp b/src/mbgl/util/chrono.cpp index ca8ebca953..f0b3f88192 100644 --- a/src/mbgl/util/chrono.cpp +++ b/src/mbgl/util/chrono.cpp @@ -1,5 +1,9 @@ #include <mbgl/util/chrono.hpp> +#include <parsedate/parsedate.h> + +#include <cstdio> + namespace mbgl { template Duration toDuration<Clock, Duration>(TimePoint); @@ -17,4 +21,35 @@ template Milliseconds asMilliseconds<Seconds>(Seconds); template Milliseconds toMilliseconds<Clock, Duration>(TimePoint); template Milliseconds toMilliseconds<SystemClock, SystemDuration>(SystemTimePoint); +namespace util { + +static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + +std::string rfc1123(SystemTimePoint timePoint) { + std::time_t time = SystemClock::to_time_t(timePoint); + std::tm info; + gmtime_r(&time, &info); + char buffer[30]; + snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday, + months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec); + return buffer; +} + +std::string iso8601(SystemTimePoint timePoint) { + std::time_t time = SystemClock::to_time_t(timePoint); + std::tm info; + gmtime_r(&time, &info); + char buffer[30]; + std::strftime(buffer, sizeof(buffer), "%F %T", &info); + return buffer; +} + +SystemTimePoint parseTimePoint(const char * timePoint) { + return SystemClock::from_time_t(parse_date(timePoint)); +} + +} // namespace util + } // namespace mbgl diff --git a/src/mbgl/util/time.cpp b/src/mbgl/util/time.cpp deleted file mode 100644 index 575ed47e1a..0000000000 --- a/src/mbgl/util/time.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include <mbgl/util/time.hpp> - -#include <cstdio> - -namespace mbgl { -namespace util { - -static const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -static const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - -std::string rfc1123(std::time_t time) { - std::tm info; - gmtime_r(&time, &info); - char buffer[30]; - snprintf(buffer, 30, "%s, %02d %s %4d %02d:%02d:%02d GMT", week[info.tm_wday], info.tm_mday, - months[info.tm_mon], 1900 + info.tm_year, info.tm_hour, info.tm_min, info.tm_sec); - return buffer; -} - -std::string iso8601(std::time_t time) { - std::tm info; - gmtime_r(&time, &info); - char buffer[30]; - std::strftime(buffer, sizeof(buffer), "%F %T", &info); - return buffer; -} - -} // namespace util -} // namespace mbgl diff --git a/src/mbgl/util/parsedate.c b/src/parsedate/parsedate.c index f888def853..46acceed75 100644 --- a/src/mbgl/util/parsedate.c +++ b/src/parsedate/parsedate.c @@ -73,7 +73,7 @@ */ -#include <mbgl/util/parsedate.h> +#include "parsedate.h" diff --git a/src/parsedate/parsedate.h b/src/parsedate/parsedate.h new file mode 100644 index 0000000000..6905e361d4 --- /dev/null +++ b/src/parsedate/parsedate.h @@ -0,0 +1,38 @@ +#ifndef HEADER_PARSEDATE_H +#define HEADER_PARSEDATE_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include <time.h> + +time_t parse_date(const char *p); + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_PARSEDATE_H */ |