bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainenstatic int tm_cmp(const struct tm *tm1, const struct tm *tm2)
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen if ((diff = tm1->tm_year - tm2->tm_year) != 0)
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen if ((diff = tm1->tm_mday - tm2->tm_mday) != 0)
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen if ((diff = tm1->tm_hour - tm2->tm_hour) != 0)
ac3de45a2b7f7411f18bf3c0f0bc8dd54519944aMartti Rannanjärvistatic inline void adjust_leap_second(struct tm *tm)
ac3de45a2b7f7411f18bf3c0f0bc8dd54519944aMartti Rannanjärvi/* Normalization done by timegm is considered a failure here, since it means
ac3de45a2b7f7411f18bf3c0f0bc8dd54519944aMartti Rannanjärvi * the timestamp is not valid as-is. Leap second 60 is adjusted to 59 before
ac3de45a2b7f7411f18bf3c0f0bc8dd54519944aMartti Rannanjärvi * this though. */
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen /* we'll do a binary search across the entire valid time_t range.
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen when gmtime()'s output matches the tm parameter, we've found the
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen correct time_t value. this also means that if tm contains invalid
11a8445dc9d6c54288e7fa930378bb4d5669a3f9Timo Sirainen values, -1 is returned. */