Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
5465cdf4
Commit
5465cdf4
authored
Jul 19, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Don't use struct tm.tm_yday from strptime
parent
f2a1c8ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
src/timegm.c
src/timegm.c
+33
-0
src/timegm.h
src/timegm.h
+5
-0
src/util.cc
src/util.cc
+1
-1
No files found.
src/timegm.c
View file @
5465cdf4
...
...
@@ -53,3 +53,36 @@ time_t nghttp2_timegm(struct tm *tm) {
return
(
time_t
)
t
;
}
/* Returns nonzero if the |y| is the leap year. The |y| is the year,
including century (e.g., 2012) */
static
int
is_leap_year
(
int
y
)
{
return
y
%
4
==
0
&&
(
y
%
100
!=
0
||
y
%
400
==
0
);
}
/* The number of days before ith month begins */
static
int
daysum
[]
=
{
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
};
time_t
nghttp2_timegm_without_yday
(
struct
tm
*
tm
)
{
int
days
;
int
num_leap_year
;
int64_t
t
;
if
(
tm
->
tm_mon
>
11
)
{
return
-
1
;
}
num_leap_year
=
count_leap_year
(
tm
->
tm_year
+
1900
)
-
count_leap_year
(
1970
);
days
=
(
tm
->
tm_year
-
70
)
*
365
+
num_leap_year
+
daysum
[
tm
->
tm_mon
]
+
tm
->
tm_mday
-
1
;
if
(
tm
->
tm_mon
>=
2
&&
is_leap_year
(
tm
->
tm_year
+
1900
))
{
++
days
;
}
t
=
((
int64_t
)
days
*
24
+
tm
->
tm_hour
)
*
3600
+
tm
->
tm_min
*
60
+
tm
->
tm_sec
;
#if SIZEOF_TIME_T == 4
if
(
t
<
INT32_MIN
||
t
>
INT32_MAX
)
{
return
-
1
;
}
#endif
/* SIZEOF_TIME_T == 4 */
return
t
;
}
src/timegm.h
View file @
5465cdf4
...
...
@@ -39,6 +39,11 @@ extern "C" {
time_t
nghttp2_timegm
(
struct
tm
*
tm
);
/* Just like nghttp2_timegm, but without using tm->tm_yday. This is
useful if we use tm from strptime, since some platforms do not
calculate tm_yday with that call. */
time_t
nghttp2_timegm_without_yday
(
struct
tm
*
tm
);
#ifdef __cplusplus
}
#endif
/* __cplusplus */
...
...
src/util.cc
View file @
5465cdf4
...
...
@@ -354,7 +354,7 @@ time_t parse_http_date(const std::string &s) {
if
(
r
==
0
)
{
return
0
;
}
return
nghttp2_timegm
(
&
tm
);
return
nghttp2_timegm
_without_yday
(
&
tm
);
}
namespace
{
...
...
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