You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.8 KiB

  1. /**
  2. * @file timestamp.h
  3. * @brief timestamp creation, conversion, and manipulation functions
  4. * @license GNU General Public License 3.0 - see LICENSE.txt
  5. */
  6. #ifndef TIMESTAMP_H
  7. #define TIMESTAMP_H
  8. #include <time.h>
  9. #include "dynamic_api.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #ifdef WIN32
  14. // this struct is compatible to struct tm
  15. typedef struct _timestamp {
  16. int tm_sec;
  17. int tm_min;
  18. int tm_hour;
  19. int tm_mday;
  20. int tm_mon;
  21. int tm_year;
  22. int tm_wday;
  23. int tm_yday;
  24. int tm_isdst;
  25. long tm_gmtoff; // offset from GMT in seconds
  26. } timestamp;
  27. #else
  28. // for time values all functions are using POSIX struct tm
  29. typedef struct tm timestamp;
  30. #endif
  31. /**
  32. * <!-- timegm_with_gmtoff() -->
  33. *
  34. * @brief Convert the broken-out time into time_t, and respect tm_gmtoff
  35. *
  36. * @retval time_t that holds the usual "seconds since epoch"
  37. *
  38. *
  39. */
  40. DYNAMIC_API time_t timegm_with_gmtoff(const timestamp* ts);
  41. /**
  42. * <!-- new_timestamp() -->
  43. *
  44. * @brief Allocate a new timestamp
  45. *
  46. * @param[in] clock initial value or 0 if not available
  47. *
  48. * @retval pointer to timestamp object or NULL if out of memory
  49. *
  50. *
  51. */
  52. DYNAMIC_API timestamp * new_timestamp(time_t clock);
  53. /**
  54. * <!-- free_timestamp() -->
  55. *
  56. * @brief Free memory occupied by timestamp
  57. *
  58. * @param[in] ts pointer to timestamp to free
  59. *
  60. *
  61. */
  62. DYNAMIC_API void free_timestamp(timestamp *ts);
  63. /**
  64. * <!-- timestamp_dup() -->
  65. *
  66. * @brief Duplicate a timestamp
  67. *
  68. * @param[in] src pointer to timestamp to duplicate
  69. *
  70. * @retval pointer to copy or NULL if out of memory
  71. *
  72. *
  73. */
  74. DYNAMIC_API timestamp * timestamp_dup(const timestamp *src);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif