timelib_private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015-2019 Derick Rethans
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef __TIMELIB_PRIVATE_H__
  25. #define __TIMELIB_PRIVATE_H__
  26. #ifdef HAVE_TIMELIB_CONFIG_H
  27. # include "timelib_config.h"
  28. #endif
  29. #ifdef HAVE_SYS_TIME_H
  30. # include <sys/time.h>
  31. #endif
  32. #ifdef _WIN32
  33. # ifdef HAVE_WINSOCK2_H
  34. # include <winsock2.h>
  35. # endif
  36. #endif
  37. #include <string.h>
  38. #ifdef HAVE_SYS_TYPES_H
  39. #include <sys/types.h>
  40. #endif
  41. #if defined(HAVE_STDINT_H)
  42. # include <stdint.h>
  43. #endif
  44. #if HAVE_UNISTD_H
  45. # include <unistd.h>
  46. #endif
  47. #if HAVE_IO_H
  48. # include <io.h>
  49. #endif
  50. #if HAVE_DIRENT_H
  51. # include <dirent.h>
  52. #endif
  53. #include <stdio.h>
  54. #include <limits.h>
  55. #define TIMELIB_SECOND 1
  56. #define TIMELIB_MINUTE 2
  57. #define TIMELIB_HOUR 3
  58. #define TIMELIB_DAY 4
  59. #define TIMELIB_MONTH 5
  60. #define TIMELIB_YEAR 6
  61. #define TIMELIB_WEEKDAY 7
  62. #define TIMELIB_SPECIAL 8
  63. #define TIMELIB_MICROSEC 9
  64. #define TIMELIB_SPECIAL_WEEKDAY 0x01
  65. #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH 0x02
  66. #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
  67. #define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH 0x01
  68. #define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH 0x02
  69. #define TIMELIB_TIME_PART_DONT_KEEP 0x00
  70. #define TIMELIB_TIME_PART_KEEP 0x01
  71. #define MINS_PER_HOUR 60
  72. #define SECS_PER_ERA TIMELIB_LL_CONST(12622780800)
  73. #define SECS_PER_DAY 86400
  74. #define SECS_PER_HOUR 3600
  75. #define USECS_PER_HOUR TIMELIB_LL_CONST(3600000000)
  76. #define DAYS_PER_WEEK 7
  77. #define DAYS_PER_YEAR 365
  78. #define DAYS_PER_LYEAR 366
  79. #define MONTHS_PER_YEAR 12
  80. /* 400*365 days + 97 leap days */
  81. #define DAYS_PER_ERA 146097
  82. #define YEARS_PER_ERA 400
  83. #define HINNANT_EPOCH_SHIFT 719468 /* 0000-03-01 instead of 1970-01-01 */
  84. #define TIMELIB_TZINFO_PHP 0x01
  85. #define TIMELIB_TZINFO_ZONEINFO 0x02
  86. #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
  87. #define TIMELIB_DEBUG(s) if (0) { s }
  88. #define TIMELIB_TIME_FREE(m) \
  89. if (m) { \
  90. timelib_free(m); \
  91. m = NULL; \
  92. }
  93. #if defined (__GNUC__)
  94. # define TIMELIB_GNUC_CHECK_VERSION(major, minor) \
  95. ((__GNUC__ > (major)) || \
  96. ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor))))
  97. #else
  98. # define TIMELIB_GNUC_CHECK_VERSION(major, minor) 0
  99. #endif
  100. #if TIMELIB_GNUC_CHECK_VERSION(7, 0)
  101. # define TIMELIB_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough));
  102. #else
  103. # define TIMELIB_BREAK_INTENTIONALLY_MISSING
  104. #endif
  105. struct _ttinfo
  106. {
  107. int32_t offset;
  108. int isdst;
  109. unsigned int abbr_idx;
  110. unsigned int isstdcnt;
  111. unsigned int isgmtcnt;
  112. };
  113. struct _tlinfo
  114. {
  115. int64_t trans;
  116. int32_t offset;
  117. };
  118. #ifndef LONG_MAX
  119. #define LONG_MAX 2147483647L
  120. #endif
  121. #ifndef LONG_MIN
  122. #define LONG_MIN (- LONG_MAX - 1)
  123. #endif
  124. #ifdef __cplusplus
  125. extern "C" {
  126. #endif
  127. /* From unixtime2tm.c */
  128. int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
  129. /* From parse_posix.c */
  130. timelib_sll timelib_ts_at_start_of_year(timelib_sll year);
  131. ttinfo* timelib_fetch_posix_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time);
  132. /* From parse_tz.c */
  133. void timelib_time_tz_abbr_update(timelib_time* tm, const char* tz_abbr);
  134. ttinfo* timelib_fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time);
  135. /* From timelib.c */
  136. int timelib_strcasecmp(const char *s1, const char *s2);
  137. int timelib_strncasecmp(const char *s1, const char *s2, size_t n);
  138. #ifdef __cplusplus
  139. } /* extern "C" */
  140. #endif
  141. #endif