Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
12ab6bb1
Commit
12ab6bb1
authored
Jan 08, 2015
by
kosak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small Mingw localtime() fix.
Thanks tberghammer for pointing it out.
https://codereview.appspot.com/185420043/
parent
c2101c28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
gtest.cc
src/gtest.cc
+18
-9
No files found.
src/gtest.cc
View file @
12ab6bb1
...
@@ -3505,19 +3505,28 @@ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
...
@@ -3505,19 +3505,28 @@ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
return
ss
.
str
();
return
ss
.
str
();
}
}
static
bool
PortableLocaltime
(
time_t
seconds
,
struct
tm
*
out
)
{
#if defined(_MSC_VER)
return
localtime_s
(
out
,
&
seconds
)
==
0
;
#elif defined(__MINGW32__) || defined(__MINGW64__)
// MINGW <time.h> provides neither localtime_r nor localtime_s, but uses
// Windows' localtime(), which has a thread-local tm buffer.
struct
tm
*
tm_ptr
=
localtime
(
&
seconds
);
// NOLINT
if
(
tm_ptr
==
NULL
)
return
false
;
*
out
=
*
tm_ptr
;
return
true
;
#else
return
localtime_r
(
&
seconds
,
out
)
!=
NULL
;
#endif
}
// Converts the given epoch time in milliseconds to a date string in the ISO
// Converts the given epoch time in milliseconds to a date string in the ISO
// 8601 format, without the timezone information.
// 8601 format, without the timezone information.
std
::
string
FormatEpochTimeInMillisAsIso8601
(
TimeInMillis
ms
)
{
std
::
string
FormatEpochTimeInMillisAsIso8601
(
TimeInMillis
ms
)
{
time_t
seconds
=
static_cast
<
time_t
>
(
ms
/
1000
);
struct
tm
time_struct
;
struct
tm
time_struct
;
#ifdef _MSC_VER
if
(
!
PortableLocaltime
(
static_cast
<
time_t
>
(
ms
/
1000
),
&
time_struct
))
if
(
localtime_s
(
&
time_struct
,
&
seconds
)
!=
0
)
return
""
;
return
""
;
// Invalid ms value
#else
if
(
localtime_r
(
&
seconds
,
&
time_struct
)
==
NULL
)
return
""
;
// Invalid ms value
#endif
// YYYY-MM-DDThh:mm:ss
// YYYY-MM-DDThh:mm:ss
return
StreamableToString
(
time_struct
.
tm_year
+
1900
)
+
"-"
+
return
StreamableToString
(
time_struct
.
tm_year
+
1900
)
+
"-"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_mon
+
1
)
+
"-"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_mon
+
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