diff options
-rw-r--r-- | include/mbgl/platform/time.hpp | 13 | ||||
-rw-r--r-- | include/mbgl/util/chrono.hpp | 4 | ||||
-rw-r--r-- | platform/android/android.cmake | 1 | ||||
-rw-r--r-- | platform/default/src/mbgl/platform/time.cpp | 11 | ||||
-rw-r--r-- | platform/ios/ios.cmake | 1 | ||||
-rw-r--r-- | platform/linux/linux.cmake | 1 | ||||
-rw-r--r-- | platform/macos/macos.cmake | 1 | ||||
-rw-r--r-- | platform/qt/qt.cmake | 1 | ||||
-rw-r--r-- | src/mbgl/util/http_header.cpp | 3 |
9 files changed, 34 insertions, 2 deletions
diff --git a/include/mbgl/platform/time.hpp b/include/mbgl/platform/time.hpp new file mode 100644 index 0000000000..8769524514 --- /dev/null +++ b/include/mbgl/platform/time.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include <chrono> + +namespace mbgl { +namespace platform { + +// Returns the current time. Abstracted because some platforms +// will not allow direct access to the current time via syscall. +std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> now(); + +} // namespace platform +} // namespace mbgl diff --git a/include/mbgl/util/chrono.hpp b/include/mbgl/util/chrono.hpp index 4de3c2d3a2..d736b4f826 100644 --- a/include/mbgl/util/chrono.hpp +++ b/include/mbgl/util/chrono.hpp @@ -1,5 +1,7 @@ #pragma once +#include <mbgl/platform/time.hpp> + #include <chrono> #include <string> @@ -19,7 +21,7 @@ using Timestamp = std::chrono::time_point<std::chrono::system_clock, Seconds>; namespace util { inline Timestamp now() { - return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::now()); + return platform::now(); } // Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT" diff --git a/platform/android/android.cmake b/platform/android/android.cmake index fd6d9e7348..6547496bce 100644 --- a/platform/android/android.cmake +++ b/platform/android/android.cmake @@ -50,6 +50,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/gfx/headless_frontend.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/gl/headless_backend.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/map/map_snapshotter.cpp + ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/platform/time.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/asset_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/database_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/file_source_manager.cpp diff --git a/platform/default/src/mbgl/platform/time.cpp b/platform/default/src/mbgl/platform/time.cpp new file mode 100644 index 0000000000..647464bb91 --- /dev/null +++ b/platform/default/src/mbgl/platform/time.cpp @@ -0,0 +1,11 @@ +#include <chrono> + +namespace mbgl { +namespace platform { + +std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> now() { + return std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()); +} + +} // namespace platform +} // namespace mbgl diff --git a/platform/ios/ios.cmake b/platform/ios/ios.cmake index 984b15840f..cab63e2824 100644 --- a/platform/ios/ios.cmake +++ b/platform/ios/ios.cmake @@ -49,6 +49,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/gfx/headless_frontend.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/map/map_snapshotter.cpp + ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/platform/time.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/asset_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/database_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/file_source_manager.cpp diff --git a/platform/linux/linux.cmake b/platform/linux/linux.cmake index 7412b09f8a..47395df7c6 100644 --- a/platform/linux/linux.cmake +++ b/platform/linux/linux.cmake @@ -18,6 +18,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/i18n/collator.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/i18n/number_format.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp + ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/platform/time.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/asset_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/database_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/file_source_manager.cpp diff --git a/platform/macos/macos.cmake b/platform/macos/macos.cmake index a0eb3eae55..38c6e41a01 100644 --- a/platform/macos/macos.cmake +++ b/platform/macos/macos.cmake @@ -42,6 +42,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/gfx/headless_frontend.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/map/map_snapshotter.cpp + ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/platform/time.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/asset_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/database_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/file_source_manager.cpp diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index a7d209a077..fdb26e5308 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -31,6 +31,7 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/gl/headless_backend.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/i18n/collator.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp + ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/platform/time.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/asset_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/database_file_source.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/file_source_manager.cpp diff --git a/src/mbgl/util/http_header.cpp b/src/mbgl/util/http_header.cpp index cdb4759d51..9777a2c806 100644 --- a/src/mbgl/util/http_header.cpp +++ b/src/mbgl/util/http_header.cpp @@ -1,5 +1,6 @@ #include <mbgl/util/http_header.hpp> +#include <mbgl/util/chrono.hpp> #include <mbgl/util/string.hpp> #include <boost/spirit/include/qi.hpp> @@ -31,7 +32,7 @@ optional<Timestamp> parseRetryHeaders(const optional<std::string>& retryAfter, if (retryAfter) { try { auto secs = std::chrono::seconds(std::stoi(*retryAfter)); - return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::now() + secs); + return std::chrono::time_point_cast<Seconds>(util::now() + secs); } catch (...) { return util::parseTimestamp((*retryAfter).c_str()); } |