Skip to content

Commit

Permalink
Fix log timestamps being off by one hour when DST is in effect. (#11385)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgchen1 authored Sep 20, 2022
1 parent 1245c63 commit 32878a1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions onnxruntime/core/common/logging/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ static minutes InitLocaltimeOffset(const time_point<system_clock>& epoch) noexce
gmtime_r(&system_time_t, &utc_tm);
#endif

// Note: mktime() expects a local time and utc_tm is not a local time.
// However, we treat utc_tm as a local time in order to compute the local time offset.
// To avoid DST inconsistency, set utc_tm's tm_isdst to match that of actual local time local_tm.
utc_tm.tm_isdst = local_tm.tm_isdst;

const double seconds = difftime(mktime(&local_tm), mktime(&utc_tm));

// minutes should be accurate enough for timezone conversion
Expand Down

0 comments on commit 32878a1

Please sign in to comment.