File tree 5 files changed +61
-0
lines changed
5 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ build /*
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.14)
2
+ project (get_time_example VERSION 0.1 LANGUAGES CXX)
3
+
4
+ set (CMAKE_CXX_STANDARD 17)
5
+
6
+ include (FetchContent)
7
+
8
+ FetchContent_Declare(
9
+ fmt
10
+ GIT_REPOSITORY "https://github.com/fmtlib/fmt"
11
+ GIT_TAG "9.1.0"
12
+ )
13
+
14
+ FetchContent_Declare(
15
+ DocTest
16
+ GIT_REPOSITORY "https://github.com/onqtam/doctest"
17
+ GIT_TAG "v2.4.11"
18
+ )
19
+
20
+ FetchContent_MakeAvailable(fmt)
21
+ FetchContent_MakeAvailable(DocTest)
22
+
23
+ add_executable (${PROJECT_NAME} example/main.cpp)
24
+ target_link_libraries (${PROJECT_NAME} fmt::fmt)
25
+ target_include_directories (${PROJECT_NAME} AFTER PUBLIC ${CMAKE_SOURCE_DIR} /include )
26
+
27
+ enable_testing ()
28
+ add_subdirectory (test )
Original file line number Diff line number Diff line change
1
+ #include " get_time.hpp"
2
+
3
+ // {fmt} for printing
4
+ #include < fmt/chrono.h>
5
+ #include < fmt/format.h>
6
+
7
+ int main () {
8
+ const auto chrono_time = mgutility::get_time (" {:%FT%T.%f%z}" , " 2023-04-16T00:05:23.999+0100" );
9
+
10
+ fmt::print (" {:%F %T}\n " , chrono_time); // prints 2023-04-15 23:05:23.999000000 ({fmt} trunk version)
11
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.14)
2
+ project (get_time_test VERSION 0.1 LANGUAGES CXX)
3
+
4
+ set (CMAKE_CXX_STANDARD 17)
5
+
6
+ include_directories (AFTER PUBLIC ${CMAKE_SOURCE_DIR} /include )
7
+
8
+ add_executable (${PROJECT_NAME} get_time_test.cpp)
9
+ target_link_libraries (${PROJECT_NAME} doctest)
Original file line number Diff line number Diff line change
1
+ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
2
+ #include " doctest/doctest.h"
3
+ #include " get_time.hpp"
4
+
5
+
6
+ TEST_CASE (" testing the iso8601 parsing" ) {
7
+ CHECK (mgutility::get_time (" {:%FT%T}" , " 2023-04-30T16:22:18" ).time_since_epoch ().count () == 1682871738000000000 );
8
+ CHECK (mgutility::get_time (" {:%FT%T%z}" , " 2023-04-30T18:22:18+0200" ).time_since_epoch ().count () == 1682871738000000000 );
9
+ CHECK (mgutility::get_time (" {:%FT%T%z}" , " 2023-04-30T16:22:18-0200" ).time_since_epoch ().count () == 1682878938000000000 );
10
+ CHECK (mgutility::get_time (" {:%FT%T.%f}" , " 2023-04-30T16:22:18.500" ).time_since_epoch ().count () == 1682871738500000000 );
11
+ CHECK (mgutility::get_time (" {:%FT%T.%f%z}" , " 2023-04-30T16:22:18.500+0100" ).time_since_epoch ().count () == 1682868138500000000 );
12
+ }
You can’t perform that action at this time.
0 commit comments