Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
06dac478
Commit
06dac478
authored
Aug 19, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time/Convert: fallback TimeGm() implementation
Move code from Parser.cxx.
parent
fdaadc19
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
36 deletions
+33
-36
Convert.cxx
src/time/Convert.cxx
+31
-4
Convert.hxx
src/time/Convert.hxx
+0
-4
Parser.cxx
src/time/Parser.cxx
+1
-27
Parser.hxx
src/time/Parser.hxx
+1
-1
No files found.
src/time/Convert.cxx
View file @
06dac478
...
@@ -67,15 +67,42 @@ LocalTime(std::chrono::system_clock::time_point tp)
...
@@ -67,15 +67,42 @@ LocalTime(std::chrono::system_clock::time_point tp)
return
*
tm
;
return
*
tm
;
}
}
#ifdef __GLIBC__
#ifndef __GLIBC__
/**
* Determine the time zone offset in a portable way.
*/
gcc_const
static
time_t
GetTimeZoneOffset
()
noexcept
{
time_t
t
=
1234567890
;
struct
tm
tm
;
tm
.
tm_isdst
=
0
;
#ifdef _WIN32
struct
tm
*
p
=
gmtime
(
&
t
);
#else
struct
tm
*
p
=
&
tm
;
gmtime_r
(
&
t
,
p
);
#endif
return
t
-
mktime
(
&
tm
);
}
#endif
/* !__GLIBC__ */
std
::
chrono
::
system_clock
::
time_point
std
::
chrono
::
system_clock
::
time_point
TimeGm
(
struct
tm
&
tm
)
noexcept
TimeGm
(
struct
tm
&
tm
)
noexcept
{
{
return
std
::
chrono
::
system_clock
::
from_time_t
(
timegm
(
&
tm
));
#ifdef __GLIBC__
}
/* timegm() is a GNU extension */
const
auto
t
=
timegm
(
&
tm
);
#else
tm
.
tm_isdst
=
0
;
const
auto
t
=
mktime
(
&
tm
)
+
GetTimeZoneOffset
();
#endif
/* !__GLIBC__ */
#endif
return
std
::
chrono
::
system_clock
::
from_time_t
(
t
);
}
std
::
chrono
::
system_clock
::
time_point
std
::
chrono
::
system_clock
::
time_point
MakeTime
(
struct
tm
&
tm
)
noexcept
MakeTime
(
struct
tm
&
tm
)
noexcept
...
...
src/time/Convert.hxx
View file @
06dac478
...
@@ -53,8 +53,6 @@ GmTime(std::chrono::system_clock::time_point tp);
...
@@ -53,8 +53,6 @@ GmTime(std::chrono::system_clock::time_point tp);
struct
tm
struct
tm
LocalTime
(
std
::
chrono
::
system_clock
::
time_point
tp
);
LocalTime
(
std
::
chrono
::
system_clock
::
time_point
tp
);
#ifdef __GLIBC__
/**
/**
* Convert a UTC-based "struct tm" to a UTC-based time point.
* Convert a UTC-based "struct tm" to a UTC-based time point.
*/
*/
...
@@ -62,8 +60,6 @@ gcc_pure
...
@@ -62,8 +60,6 @@ gcc_pure
std
::
chrono
::
system_clock
::
time_point
std
::
chrono
::
system_clock
::
time_point
TimeGm
(
struct
tm
&
tm
)
noexcept
;
TimeGm
(
struct
tm
&
tm
)
noexcept
;
#endif
/**
/**
* Convert a local "struct tm" to a UTC-based time point.
* Convert a local "struct tm" to a UTC-based time point.
*/
*/
...
...
src/time/Parser.cxx
View file @
06dac478
/*
/*
* Copyright
(C) 2014-2017
Max Kellermann <max.kellermann@gmail.com>
* Copyright
2014-2019
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -29,31 +29,12 @@
...
@@ -29,31 +29,12 @@
#include "Parser.hxx"
#include "Parser.hxx"
#include "Convert.hxx"
#include "Convert.hxx"
#include "util/Compiler.h"
#include <stdexcept>
#include <stdexcept>
#include <assert.h>
#include <assert.h>
#include <time.h>
#include <time.h>
#if !defined(__GLIBC__) && !defined(_WIN32)
/**
* Determine the time zone offset in a portable way.
*/
gcc_const
static
time_t
GetTimeZoneOffset
()
noexcept
{
time_t
t
=
1234567890
;
struct
tm
tm
;
tm
.
tm_isdst
=
0
;
gmtime_r
(
&
t
,
&
tm
);
return
t
-
mktime
(
&
tm
);
}
#endif
std
::
chrono
::
system_clock
::
time_point
std
::
chrono
::
system_clock
::
time_point
ParseTimePoint
(
const
char
*
s
,
const
char
*
format
)
ParseTimePoint
(
const
char
*
s
,
const
char
*
format
)
{
{
...
@@ -71,13 +52,6 @@ ParseTimePoint(const char *s, const char *format)
...
@@ -71,13 +52,6 @@ ParseTimePoint(const char *s, const char *format)
if
(
end
==
nullptr
||
*
end
!=
0
)
if
(
end
==
nullptr
||
*
end
!=
0
)
throw
std
::
runtime_error
(
"Failed to parse time stamp"
);
throw
std
::
runtime_error
(
"Failed to parse time stamp"
);
#ifdef __GLIBC__
/* timegm() is a GNU extension */
return
TimeGm
(
tm
);
return
TimeGm
(
tm
);
#else
tm
.
tm_isdst
=
0
;
const
auto
t
=
mktime
(
&
tm
)
+
GetTimeZoneOffset
();
return
std
::
chrono
::
system_clock
::
from_time_t
(
t
);
#endif
/* !__GLIBC__ */
#endif
/* !_WIN32 */
#endif
/* !_WIN32 */
}
}
src/time/Parser.hxx
View file @
06dac478
/*
/*
* Copyright
(C) 2014-2017
Max Kellermann <max.kellermann@gmail.com>
* Copyright
2014-2019
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
...
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