pgtime.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pgtime.h
  4. * PostgreSQL internal timezone library
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. *
  8. * IDENTIFICATION
  9. * src/include/pgtime.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef _PGTIME_H
  14. #define _PGTIME_H
  15. /*
  16. * The API of this library is generally similar to the corresponding
  17. * C library functions, except that we use pg_time_t which (we hope) is
  18. * 64 bits wide, and which is most definitely signed not unsigned.
  19. */
  20. typedef int64 pg_time_t;
  21. /*
  22. * Data structure representing a broken-down timestamp.
  23. *
  24. * CAUTION: the IANA timezone library (src/timezone/) follows the POSIX
  25. * convention that tm_mon counts from 0 and tm_year is relative to 1900.
  26. * However, Postgres' datetime functions generally treat tm_mon as counting
  27. * from 1 and tm_year as relative to 1 BC. Be sure to make the appropriate
  28. * adjustments when moving from one code domain to the other.
  29. */
  30. struct pg_tm
  31. {
  32. int tm_sec;
  33. int tm_min;
  34. int tm_hour;
  35. int tm_mday;
  36. int tm_mon; /* see above */
  37. int tm_year; /* see above */
  38. int tm_wday;
  39. int tm_yday;
  40. int tm_isdst;
  41. long int tm_gmtoff;
  42. const char *tm_zone;
  43. };
  44. /* These structs are opaque outside the timezone library */
  45. typedef struct pg_tz pg_tz;
  46. typedef struct pg_tzenum pg_tzenum;
  47. /* Maximum length of a timezone name (not including trailing null) */
  48. #define TZ_STRLEN_MAX 255
  49. /* these functions are in localtime.c */
  50. extern struct pg_tm *pg_localtime(const pg_time_t *timep, const pg_tz *tz);
  51. extern struct pg_tm *pg_gmtime(const pg_time_t *timep);
  52. extern int pg_next_dst_boundary(const pg_time_t *timep,
  53. long int *before_gmtoff,
  54. int *before_isdst,
  55. pg_time_t *boundary,
  56. long int *after_gmtoff,
  57. int *after_isdst,
  58. const pg_tz *tz);
  59. extern bool pg_interpret_timezone_abbrev(const char *abbrev,
  60. const pg_time_t *timep,
  61. long int *gmtoff,
  62. int *isdst,
  63. const pg_tz *tz);
  64. extern bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff);
  65. extern const char *pg_get_timezone_name(pg_tz *tz);
  66. extern bool pg_tz_acceptable(pg_tz *tz);
  67. /* these functions are in strftime.c */
  68. extern size_t pg_strftime(char *s, size_t max, const char *format,
  69. const struct pg_tm *tm);
  70. /* these functions and variables are in pgtz.c */
  71. extern PGDLLIMPORT pg_tz *session_timezone;
  72. extern PGDLLIMPORT pg_tz *log_timezone;
  73. extern void pg_timezone_initialize(void);
  74. extern pg_tz *pg_tzset(const char *tzname);
  75. extern pg_tz *pg_tzset_offset(long gmtoffset);
  76. extern pg_tzenum *pg_tzenumerate_start(void);
  77. extern pg_tz *pg_tzenumerate_next(pg_tzenum *dir);
  78. extern void pg_tzenumerate_end(pg_tzenum *dir);
  79. #endif /* _PGTIME_H */