logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

utils_timegm.c (628B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #define _DEFAULT_SOURCE // tm_gmtoff/tm_zone, timegm (POSIX.1-2024 mktime() future directions)
  5. #include "./datetime_parse.h"
  6. #include <time.h>
  7. // Wrap timegm() to still get portable behavior while setting tm_gmtoff directly
  8. // Effectively the opposite of gmtime()
  9. time_t
  10. utils_timegm(struct tm *tm)
  11. {
  12. long gmtoff = tm->tm_gmtoff;
  13. tm->tm_isdst = 0;
  14. tm->tm_gmtoff = 0;
  15. tm->tm_zone = "UTC";
  16. time_t ret = timegm(tm);
  17. return ret - gmtoff;
  18. }