From ee1d700a9bc764c86502978b5538df44aaa66905 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Mon, 20 Apr 2020 16:37:24 +0300 Subject: [core] Add platform abstractions for utils::now() Some platforms might require special permissions or custom APIs to access the current time of the day. --- include/mbgl/platform/time.hpp | 13 +++++++++++++ include/mbgl/util/chrono.hpp | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 include/mbgl/platform/time.hpp (limited to 'include') 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 + +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 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 + #include #include @@ -19,7 +21,7 @@ using Timestamp = std::chrono::time_point; namespace util { inline Timestamp now() { - return std::chrono::time_point_cast(std::chrono::system_clock::now()); + return platform::now(); } // Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT" -- cgit v1.2.1