timelib_private.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 SECS_PER_ERA TIMELIB_LL_CONST(12622780800)
  70. #define SECS_PER_DAY 86400
  71. #define DAYS_PER_YEAR 365
  72. #define DAYS_PER_LYEAR 366
  73. /* 400*365 days + 97 leap days */
  74. #define DAYS_PER_LYEAR_PERIOD 146097
  75. #define YEARS_PER_LYEAR_PERIOD 400
  76. #define TIMELIB_TZINFO_PHP 0x01
  77. #define TIMELIB_TZINFO_ZONEINFO 0x02
  78. #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
  79. #define TIMELIB_DEBUG(s) if (0) { s }
  80. #define TIMELIB_TIME_FREE(m) \
  81. if (m) { \
  82. timelib_free(m); \
  83. m = NULL; \
  84. }
  85. struct _ttinfo
  86. {
  87. int32_t offset;
  88. int isdst;
  89. unsigned int abbr_idx;
  90. unsigned int isstdcnt;
  91. unsigned int isgmtcnt;
  92. };
  93. struct _tlinfo
  94. {
  95. int64_t trans;
  96. int32_t offset;
  97. };
  98. #ifndef LONG_MAX
  99. #define LONG_MAX 2147483647L
  100. #endif
  101. #ifndef LONG_MIN
  102. #define LONG_MIN (- LONG_MAX - 1)
  103. #endif
  104. /* From unixtime2tm.c */
  105. int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
  106. /* From parse_tz.c */
  107. void timelib_time_tz_abbr_update(timelib_time* tm, char* tz_abbr);
  108. /* From timelib.c */
  109. int timelib_strcasecmp(const char *s1, const char *s2);
  110. int timelib_strncasecmp(const char *s1, const char *s2, size_t n);
  111. #endif