summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2020-04-20 16:37:24 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2020-04-20 19:03:46 +0300
commitee1d700a9bc764c86502978b5538df44aaa66905 (patch)
treeeee57715e5963a0057ce77ae44143615c3257f93 /include
parent71ce52d35f8421c89f6112b83061613937b2836c (diff)
downloadqtlocation-mapboxgl-ee1d700a9bc764c86502978b5538df44aaa66905.tar.gz
[core] Add platform abstractions for utils::now()
Some platforms might require special permissions or custom APIs to access the current time of the day.
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/platform/time.hpp13
-rw-r--r--include/mbgl/util/chrono.hpp4
2 files changed, 16 insertions, 1 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"