Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Özgür Ozan Sen
ogs
Commits
7743a35f
Commit
7743a35f
authored
8 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[BL] added datetime formatting function
parent
b88fb2f1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseLib/DateTools.cpp
+14
-0
14 additions, 0 deletions
BaseLib/DateTools.cpp
BaseLib/DateTools.h
+12
-1
12 additions, 1 deletion
BaseLib/DateTools.h
with
26 additions
and
1 deletion
BaseLib/DateTools.cpp
+
14
−
0
View file @
7743a35f
...
...
@@ -16,6 +16,7 @@
#include
<cmath>
#include
<cstdlib>
#include
<ctime>
#include
<sstream>
#include
<logog/include/logog.hpp>
...
...
@@ -114,4 +115,17 @@ int xmlDate2int(const std::string &s)
}
return
0
;
}
std
::
string
formatDate
(
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
const
&
time
)
{
auto
const
time_t
=
std
::
chrono
::
system_clock
::
to_time_t
(
time
);
char
time_str
[
100
];
if
(
std
::
strftime
(
time_str
,
sizeof
(
time_str
),
"%F %T%z"
,
std
::
localtime
(
&
time_t
)))
{
return
time_str
;
}
else
{
return
"FAILED FORMATTING THE GIVEN TIME POINT."
;
}
}
}
// end namespace BaseLib
This diff is collapsed.
Click to expand it.
BaseLib/DateTools.h
+
12
−
1
View file @
7743a35f
...
...
@@ -15,9 +15,11 @@
#ifndef DATETOOLS_H
#define DATETOOLS_H
#include
<chrono>
#include
<string>
namespace
BaseLib
{
namespace
BaseLib
{
/**
* Converts three integers representing a date into a double.
...
...
@@ -55,6 +57,15 @@ int strDate2int(const std::string &s);
*/
int
xmlDate2int
(
const
std
::
string
&
s
);
/**
* Formats the given time point according to RFC 3339 (cf. man-page of the unix
* date utility).
*
* Example: 2006-08-14 02:34:56-06:00
*/
std
::
string
formatDate
(
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
const
&
time
);
}
// namespace BaseLib
#endif //DATETOOLS_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment