szaszm commented on a change in pull request #840:
URL: https://github.com/apache/nifi-minifi-cpp/pull/840#discussion_r455882026
##########
File path: libminifi/include/utils/TimeUtil.h
##########
@@ -108,23 +144,9 @@ inline int64_t parseDateTimeStr(const std::string &str) {
timeinfo.tm_hour = hours;
timeinfo.tm_min = minutes;
timeinfo.tm_sec = seconds;
+ timeinfo.tm_isdst = 0;
- /* Get local timezone offset */
- time_t utc = time(nullptr);
- struct tm now_tm = *gmtime(&utc); // NOLINT
- now_tm.tm_isdst = 0;
- time_t local = mktime(&now_tm);
- if (local == -1) {
- return -1;
- }
- int64_t timezone_offset = utc - local;
-
- /* Convert parsed date */
- time_t time = mktime(&timeinfo);
- if (time == -1) {
- return -1;
- }
- return time + timezone_offset;
+ return static_cast<int64_t>(mkgmtime(&timeinfo));
Review comment:
1. Sorry, I got too carried away with the UTC/localtime issue that I
didn't even look at the signature of `strptime`.
2. I believe `mkgmtime` / [`timegm`](https://linux.die.net/man/3/timegm)
([code](https://code.woboq.org/userspace/glibc/time/timegm.c.html), don't use
this) have to deal with some of these issues, too, e.g. leap seconds occur in
UTC.
3. You might find
[`parse`](https://howardhinnant.github.io/date/date.html#parse) interesting
from [HowardHinnant/date](https://github.com/HowardHinnant/date), the basis of
C++20 date extensions.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]