Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
88
Issues
88
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
c54f28d2
Commit
c54f28d2
authored
Oct 11, 2016
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conditionally use strptime if we don’t have std::get_time
parent
dfc0793e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
louloulibs/CMakeLists.txt
louloulibs/CMakeLists.txt
+13
-0
louloulibs/louloulibs.h.cmake
louloulibs/louloulibs.h.cmake
+2
-1
louloulibs/utils/time.cpp
louloulibs/utils/time.cpp
+11
-0
No files found.
louloulibs/CMakeLists.txt
View file @
c54f28d2
...
...
@@ -143,4 +143,17 @@ if(SYSTEMD_FOUND)
target_link_libraries
(
xmpplib
${
SYSTEMD_LIBRARIES
}
)
endif
()
#
## Check if we have std::get_time
#
include
(
CheckCXXSourceCompiles
)
check_cxx_source_compiles
(
"
#include <iomanip>
int main()
{ std::get_time(nullptr,
\"\"
); }"
HAS_GET_TIME
)
mark_as_advanced
(
HAS_GET_TIME
)
configure_file
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/louloulibs.h.cmake
${
CMAKE_BINARY_DIR
}
/src/louloulibs.h
)
louloulibs/louloulibs.h.cmake
View file @
c54f28d2
...
...
@@ -6,4 +6,5 @@
#cmakedefine BOTAN_FOUND
#cmakedefine CARES_FOUND
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
\ No newline at end of file
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
#cmakedefine HAS_GET_TIME
louloulibs/utils/time.cpp
View file @
c54f28d2
...
...
@@ -5,6 +5,8 @@
#include <iomanip>
#include <locale>
#include "louloulibs.h"
namespace
utils
{
std
::
string
to_string
(
const
std
::
time_t
&
timestamp
)
...
...
@@ -20,6 +22,7 @@ std::time_t parse_datetime(const std::string& stamp)
{
static
const
char
*
format
=
"%Y-%m-%dT%H:%M:%S"
;
std
::
tm
t
=
{};
#ifdef HAS_GET_TIME
std
::
istringstream
ss
(
stamp
);
ss
.
imbue
(
std
::
locale
(
"en_US.utf-8"
));
...
...
@@ -27,6 +30,14 @@ std::time_t parse_datetime(const std::string& stamp)
ss
>>
std
::
get_time
(
&
t
,
format
)
>>
timezone
;
if
(
ss
.
fail
())
return
-
1
;
#else
/* Y - m - d T H : M : S */
constexpr
std
::
size_t
stamp_size_without_tz
=
4
+
1
+
2
+
1
+
2
+
1
+
2
+
1
+
2
+
1
+
2
;
if
(
!
strptime
(
stamp
.
data
(),
format
,
&
t
))
{
return
-
1
;
}
const
std
::
string
timezone
(
stamp
.
data
()
+
stamp_size_without_tz
);
#endif
if
(
timezone
.
empty
())
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment