utils_timegm.c (628B)
- // utils-std: Collection of commonly available Unix tools
- // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #define _DEFAULT_SOURCE // tm_gmtoff/tm_zone, timegm (POSIX.1-2024 mktime() future directions)
- #include "./datetime_parse.h"
- #include <time.h>
- // Wrap timegm() to still get portable behavior while setting tm_gmtoff directly
- // Effectively the opposite of gmtime()
- time_t
- utils_timegm(struct tm *tm)
- {
- long gmtoff = tm->tm_gmtoff;
- tm->tm_isdst = 0;
- tm->tm_gmtoff = 0;
- tm->tm_zone = "UTC";
- time_t ret = timegm(tm);
- return ret - gmtoff;
- }