aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/chrono.cpp
diff options
context:
space:
mode:
authorCurtis J Bezault <curtbezault@gmail.com>2019-07-24 14:26:34 -0700
committerGitHub <noreply@github.com>2019-07-24 14:26:34 -0700
commitd60047280dcdafabc45f456cd7f86b836387e0f9 (patch)
treefb5e98d1e16548635a96a5c49e7981db06a9c6f8 /toolsrc/src/vcpkg-test/chrono.cpp
parent0c7669d009548616aeb754276deea974ba7a53c3 (diff)
parentaeecc01fbd9b888a186a407532af679eacdaab2c (diff)
downloadvcpkg-d60047280dcdafabc45f456cd7f86b836387e0f9.tar.gz
vcpkg-d60047280dcdafabc45f456cd7f86b836387e0f9.zip
Merge branch 'master' into external_file_abi
Diffstat (limited to 'toolsrc/src/vcpkg-test/chrono.cpp')
-rw-r--r--toolsrc/src/vcpkg-test/chrono.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg-test/chrono.cpp b/toolsrc/src/vcpkg-test/chrono.cpp
new file mode 100644
index 000000000..306217ad0
--- /dev/null
+++ b/toolsrc/src/vcpkg-test/chrono.cpp
@@ -0,0 +1,34 @@
+#include <vcpkg-test/catch.h>
+
+#include <vcpkg/base/chrono.h>
+
+namespace Chrono = vcpkg::Chrono;
+
+TEST_CASE ("parse time", "[chrono]")
+{
+ auto timestring = "1990-02-03T04:05:06.0Z";
+ auto maybe_time = Chrono::CTime::parse(timestring);
+
+ REQUIRE(maybe_time.has_value());
+ REQUIRE(maybe_time.get()->to_string() == timestring);
+}
+
+TEST_CASE ("parse blank time", "[chrono]")
+{
+ auto maybe_time = Chrono::CTime::parse("");
+
+ REQUIRE_FALSE(maybe_time.has_value());
+}
+
+TEST_CASE ("difference of times", "[chrono]")
+{
+ auto maybe_time1 = Chrono::CTime::parse("1990-02-03T04:05:06.0Z");
+ auto maybe_time2 = Chrono::CTime::parse("1990-02-10T04:05:06.0Z");
+
+ REQUIRE(maybe_time1.has_value());
+ REQUIRE(maybe_time2.has_value());
+
+ auto delta = maybe_time2.get()->to_time_point() - maybe_time1.get()->to_time_point();
+
+ REQUIRE(std::chrono::duration_cast<std::chrono::hours>(delta).count() == 24 * 7);
+}