Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
dCache
cta
Commits
52d33a49
Commit
52d33a49
authored
7 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Create util function to print out local time.
parent
25cc2a1a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/utils/UtilsTest.cpp
+9
-0
9 additions, 0 deletions
common/utils/UtilsTest.cpp
common/utils/utils.cpp
+17
-0
17 additions, 0 deletions
common/utils/utils.cpp
common/utils/utils.hpp
+6
-0
6 additions, 0 deletions
common/utils/utils.hpp
with
32 additions
and
0 deletions
common/utils/UtilsTest.cpp
+
9
−
0
View file @
52d33a49
...
...
@@ -659,4 +659,13 @@ TEST_F(cta_UtilsTest, ellipses) {
ASSERT_EQ
(
"[...]0ABCDEF"
,
preEllipsis
(
"1234567890ABCDEF"
,
12
));
}
TEST_F
(
cta_UtilsTest
,
DISABLED_currentTime
)
{
/* This test is disabled as it prints our similar, yet slightly different dates,
* so it would be complex to automate.
* Just run with: "cta-unitTests --gtest_filter=*currentTime --gtest_also_run_disabled_tests" */
using
namespace
cta
::
utils
;
::
system
(
"date
\"
+%h %e %H:%M:%S.%N
\"
"
);
std
::
cout
<<
getCurrentLocalTime
()
<<
std
::
endl
;
}
}
// namespace unitTests
This diff is collapsed.
Click to expand it.
common/utils/utils.cpp
+
17
−
0
View file @
52d33a49
...
...
@@ -780,5 +780,22 @@ void copyString(char *const dst, const size_t dstSize, const std::string &src) {
*
(
dst
+
dstSize
-
1
)
=
'\0'
;
// Ensure destination string is null terminated
}
//-----------------------------------------------------------------------------
// getCurrentLocalTime
//-----------------------------------------------------------------------------
std
::
string
getCurrentLocalTime
()
{
::
timeval
tv
;
gettimeofday
(
&
tv
,
nullptr
);
time_t
now
=
(
time_t
)
tv
.
tv_sec
;
struct
tm
*
localNow
;
::
time
(
&
now
);
localNow
=
::
localtime
(
&
now
);
char
buff
[
80
];
char
buff2
[
10
];
::
strftime
(
buff
,
sizeof
(
buff
),
"%b %e %H:%M:%S."
,
localNow
);
::
snprintf
(
buff2
,
sizeof
(
buff2
),
"%06ld"
,
tv
.
tv_usec
);
return
std
::
string
(
buff
)
+
std
::
string
(
buff2
);
}
}
// namespace utils
}
// namespace cta
This diff is collapsed.
Click to expand it.
common/utils/utils.hpp
+
6
−
0
View file @
52d33a49
...
...
@@ -364,6 +364,12 @@ namespace utils {
const
std
::
string
&
src
)
{
copyString
(
dst
,
dstSize
,
src
);
}
/**
* Returns the current time, in the local time zone, formated for logging.
* @return the foramtted time.
*/
std
::
string
getCurrentLocalTime
();
}
// namespace utils
...
...
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