util_time.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file util_time.h
  18. * @brief Apache date-time handling functions
  19. *
  20. * @defgroup APACHE_CORE_TIME Date-time handling functions
  21. * @ingroup APACHE_CORE
  22. * @{
  23. */
  24. #ifndef APACHE_UTIL_TIME_H
  25. #define APACHE_UTIL_TIME_H
  26. #include "apr.h"
  27. #include "apr_time.h"
  28. #include "httpd.h"
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* Maximum delta from the current time, in seconds, for a past time
  33. * to qualify as "recent" for use in the ap_explode_recent_*() functions:
  34. * (Must be a power of two minus one!)
  35. */
  36. #define AP_TIME_RECENT_THRESHOLD 15
  37. /* Options for ap_recent_ctime_ex */
  38. /* No extension */
  39. #define AP_CTIME_OPTION_NONE 0x0
  40. /* Add sub second timestamps with micro second resolution */
  41. #define AP_CTIME_OPTION_USEC 0x1
  42. /* Use more compact ISO 8601 format */
  43. #define AP_CTIME_OPTION_COMPACT 0x2
  44. /**
  45. * convert a recent time to its human readable components in local timezone
  46. * @param tm the exploded time
  47. * @param t the time to explode: MUST be within the last
  48. * AP_TIME_RECENT_THRESHOLD seconds
  49. * @note This is a faster alternative to apr_time_exp_lt that uses
  50. * a cache of pre-exploded time structures. It is useful for things
  51. * that need to explode the current time multiple times per second,
  52. * like loggers.
  53. * @return APR_SUCCESS iff successful
  54. */
  55. AP_DECLARE(apr_status_t) ap_explode_recent_localtime(apr_time_exp_t *tm,
  56. apr_time_t t);
  57. /**
  58. * convert a recent time to its human readable components in GMT timezone
  59. * @param tm the exploded time
  60. * @param t the time to explode: MUST be within the last
  61. * AP_TIME_RECENT_THRESHOLD seconds
  62. * @note This is a faster alternative to apr_time_exp_gmt that uses
  63. * a cache of pre-exploded time structures. It is useful for things
  64. * that need to explode the current time multiple times per second,
  65. * like loggers.
  66. * @return APR_SUCCESS iff successful
  67. */
  68. AP_DECLARE(apr_status_t) ap_explode_recent_gmt(apr_time_exp_t *tm,
  69. apr_time_t t);
  70. /**
  71. * format a recent timestamp in the ctime() format.
  72. * @param date_str String to write to.
  73. * @param t the time to convert
  74. * @note Consider using ap_recent_ctime_ex instead.
  75. * @return APR_SUCCESS iff successful
  76. */
  77. AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t);
  78. /**
  79. * format a recent timestamp in an extended ctime() format.
  80. * @param date_str String to write to.
  81. * @param t the time to convert
  82. * @param option Additional formatting options (AP_CTIME_OPTION_*).
  83. * @param len Pointer to an int containing the length of the provided buffer.
  84. * On successful return it contains the number of bytes written to the
  85. * buffer.
  86. * @return APR_SUCCESS iff successful, APR_ENOMEM if buffer was to short.
  87. */
  88. AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
  89. int option, int *len);
  90. /**
  91. * format a recent timestamp in the RFC822 format
  92. * @param date_str String to write to (must have length >= APR_RFC822_DATE_LEN)
  93. * @param t the time to convert
  94. */
  95. AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* !APACHE_UTIL_TIME_H */
  100. /** @} */