Revision: 77347
          http://sourceforge.net/p/brlcad/code/77347
Author:   starseeker
Date:     2020-10-06 19:51:26 +0000 (Tue, 06 Oct 2020)
Log Message:
-----------
It may be a while before it gets used, but stash the core piece needed for a 
time delta calculator using date.h, which is close to what's being considered 
for C++20.  Eventually, we can use this and replace the explicit math in the 
dreport_src logic in misc/CMake/BRLCAD_Util.cmake - stashing now so I remember 
how to do this next time.

Modified Paths:
--------------
    brlcad/trunk/misc/CMake/CMakeLists.txt

Added Paths:
-----------
    brlcad/trunk/misc/CMake/date_delta.cpp

Modified: brlcad/trunk/misc/CMake/CMakeLists.txt
===================================================================
--- brlcad/trunk/misc/CMake/CMakeLists.txt      2020-10-06 18:33:20 UTC (rev 
77346)
+++ brlcad/trunk/misc/CMake/CMakeLists.txt      2020-10-06 19:51:26 UTC (rev 
77347)
@@ -84,6 +84,7 @@
   compat/test_strtok_r.c
   configure_prefix.sh
   configure_suffix.sh
+  date_delta.cpp
   distcheck_in_src_dir.cmake.in
   distcheck_no_tcl.cmake.in
   distcheck_repo_verify.cmake.in

Added: brlcad/trunk/misc/CMake/date_delta.cpp
===================================================================
--- brlcad/trunk/misc/CMake/date_delta.cpp                              (rev 0)
+++ brlcad/trunk/misc/CMake/date_delta.cpp      2020-10-06 19:51:26 UTC (rev 
77347)
@@ -0,0 +1,48 @@
+/*                  D A T E _ D E L T A . C P P
+ * BRL-CAD
+ *
+ * Published in 2020 by the United States Government.
+ * This work is in the public domain.
+ *
+ */
+/** @file date_delta.cpp
+ *
+ * Delta calculations using https://github.com/HowardHinnant/date, which
+ * is close to what is being considered for C++20.
+ *
+ */
+
+#include "date.h"
+#include <iostream>
+
+int
+main()
+{
+    long t1 = 1602012807;
+    long t2 = 1602114000;
+    std::time_t s1 = std::time_t(t1);
+    std::time_t s2 = std::time_t(t2);
+    std::chrono::system_clock::time_point tp1 = 
std::chrono::system_clock::from_time_t(s1);
+    std::chrono::system_clock::time_point tp2 = 
std::chrono::system_clock::from_time_t(s2);
+
+    auto dd = date::floor<date::days>(tp2) - date::floor<date::days>(tp1);
+    if (dd.count())
+       std::cout << "delta(dys): " << dd.count() << "\n";
+
+    auto dtime = 
date::make_time(std::chrono::duration_cast<std::chrono::milliseconds>(tp2-tp1));
+    if (dtime.hours().count())
+       std::cout << "delta(hrs): " << dtime.hours().count() << "\n";
+    if (dtime.minutes().count())
+       std::cout << "delta(min): " << dtime.minutes().count() << "\n";
+    if (dtime.seconds().count())
+       std::cout << "delta(sec): " << dtime.seconds().count() << "\n";
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8


Property changes on: brlcad/trunk/misc/CMake/date_delta.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to