Skip to content

Commit

Permalink
utime.h: fix timezone issue in round_to_* funcs.
Browse files Browse the repository at this point in the history
gmtime_r converts local time to UTC, however mktime only takes an
argument as local time. Use localtime_r instead of gmtime_r will fix.

Fixes: #14862

Reported-by: isyippee <yippee_liu@163.com>
Signed-off-by: Zhao Chao <zhaochao1984@gmail.com>
(cherry picked from commit c914f28)
  • Loading branch information
zhaochao authored and smithfarm committed Oct 15, 2016
1 parent 65e8bbc commit aaa6087
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/include/utime.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class utime_t {
utime_t round_to_minute() {
struct tm bdt;
time_t tt = sec();
gmtime_r(&tt, &bdt);
localtime_r(&tt, &bdt);
bdt.tm_sec = 0;
tt = mktime(&bdt);
return utime_t(tt, 0);
Expand All @@ -157,7 +157,7 @@ class utime_t {
utime_t round_to_hour() {
struct tm bdt;
time_t tt = sec();
gmtime_r(&tt, &bdt);
localtime_r(&tt, &bdt);
bdt.tm_sec = 0;
bdt.tm_min = 0;
tt = mktime(&bdt);
Expand Down

0 comments on commit aaa6087

Please sign in to comment.