apr_time.inc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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 apr_time.h
  18. * @brief APR Time Library
  19. }
  20. {#include "apr.h"
  21. #include "apr_pools.h"
  22. #include "apr_errno.h"}
  23. {
  24. * @defgroup apr_time Time Routines
  25. * @ingroup APR
  26. }
  27. { month names }
  28. //APR_DECLARE_DATA extern const char apr_month_snames[12][4];
  29. { day names }
  30. //APR_DECLARE_DATA extern const char apr_day_snames[7][4];
  31. { number of microseconds since 00:00:00 january 1, 1970 UTC }
  32. type
  33. apr_time_t = apr_int64_t;
  34. Papr_time_t = ^apr_time_t;
  35. { mechanism to properly type apr_time_t literals }
  36. //#define APR_TIME_C(val) APR_INT64_C(val)
  37. { mechanism to properly print apr_time_t values }
  38. // APR_TIME_T_FMT = APR_INT64_T_FMT;
  39. { intervals for I/O timeouts, in microseconds }
  40. apr_interval_time_t = apr_int64_t;
  41. Papr_interval_time_t = ^apr_interval_time_t;
  42. { short interval for I/O timeouts, in microseconds }
  43. apr_short_interval_time_t = apr_int32_t;
  44. { number of microseconds per second }
  45. // APR_USEC_PER_SEC APR_TIME_C(1000000)
  46. { @return apr_time_t as a second }
  47. //#define apr_time_sec(time) ((time) / APR_USEC_PER_SEC)
  48. { @return apr_time_t as a usec }
  49. //#define apr_time_usec(time) ((time) % APR_USEC_PER_SEC)
  50. { @return apr_time_t as a msec }
  51. //#define apr_time_msec(time) (((time) / 1000) % 1000)
  52. { @return apr_time_t as a msec }
  53. //#define apr_time_as_msec(time) ((time) / 1000)
  54. { @return a second as an apr_time_t }
  55. //#define apr_time_from_sec(sec) ((apr_time_t)(sec) * APR_USEC_PER_SEC)
  56. { @return a second and usec combination as an apr_time_t }
  57. //#define apr_time_make(sec, usec) ((apr_time_t)(sec) * APR_USEC_PER_SEC \
  58. // + (apr_time_t)(usec))
  59. {
  60. * @return the current time
  61. }
  62. function apr_time_now: apr_time_t;
  63. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  64. external LibAPR name LibNamePrefix + 'apr_time_now' + LibSuff0;
  65. { @see apr_time_exp_t }
  66. type
  67. Papr_time_exp_t = ^apr_time_exp_t;
  68. {
  69. * a structure similar to ANSI struct tm with the following differences:
  70. * - tm_usec isn't an ANSI field
  71. * - tm_gmtoff isn't an ANSI field (it's a bsdism)
  72. }
  73. apr_time_exp_t = record
  74. { microseconds past tm_sec }
  75. tm_usec: apr_int32_t;
  76. { (0-61) seconds past tm_min }
  77. tm_sec: apr_int32_t;
  78. { (0-59) minutes past tm_hour }
  79. tm_min: apr_int32_t;
  80. { (0-23) hours past midnight }
  81. tm_hour: apr_int32_t;
  82. { (1-31) day of the month }
  83. tm_mday: apr_int32_t;
  84. { (0-11) month of the year }
  85. tm_mon: apr_int32_t;
  86. { year since 1900 }
  87. tm_year: apr_int32_t;
  88. { (0-6) days since sunday }
  89. tm_wday: apr_int32_t;
  90. { (0-365) days since jan 1 }
  91. tm_yday: apr_int32_t;
  92. { daylight saving time }
  93. tm_isdst: apr_int32_t;
  94. { seconds east of UTC }
  95. tm_gmtoff: apr_int32_t;
  96. end;
  97. {
  98. * convert an ansi time_t to an apr_time_t
  99. * @param result the resulting apr_time_t
  100. * @param input the time_t to convert
  101. }
  102. function apr_time_ansi_put(result: Papr_time_t;
  103. input: time_t): apr_status_t;
  104. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  105. external LibAPR name LibNamePrefix + 'apr_time_ansi_put' + LibSuff8;
  106. {
  107. * convert a time to its human readable components using an offset
  108. * from GMT
  109. * @param result the exploded time
  110. * @param input the time to explode
  111. * @param offs the number of seconds offset to apply
  112. }
  113. function apr_time_exp_tz(result: Papr_time_exp_t;
  114. input: apr_time_t; offs: apr_int32_t): apr_status_t;
  115. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  116. external LibAPR name LibNamePrefix + 'apr_time_exp_tz' + LibSuff16;
  117. { @deprecated @see apr_time_exp_tz }
  118. function apr_explode_time(result: Papr_time_exp_t;
  119. input: apr_time_t; offs: apr_int32_t): apr_status_t;
  120. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  121. external LibAPR name LibNamePrefix + 'apr_explode_time' + LibSuff16;
  122. {
  123. * convert a time to its human readable components in GMT timezone
  124. * @param result the exploded time
  125. * @param input the time to explode
  126. }
  127. function apr_time_exp_gmt(result: Papr_time_exp_t;
  128. input: apr_time_t): apr_status_t;
  129. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  130. external LibAPR name LibNamePrefix + 'apr_time_exp_gmt' + LibSuff12;
  131. {
  132. * convert a time to its human readable components in local timezone
  133. * @param result the exploded time
  134. * @param input the time to explode
  135. }
  136. function apr_time_exp_lt(result: Papr_time_exp_t;
  137. input: apr_time_t): apr_status_t;
  138. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  139. external LibAPR name LibNamePrefix + 'apr_time_exp_lt' + LibSuff12;
  140. { @deprecated @see apr_time_exp_lt }
  141. function apr_explode_localtime(result: Papr_time_exp_t;
  142. input: apr_time_t): apr_status_t;
  143. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  144. external LibAPR name LibNamePrefix + 'apr_explode_localtime' + LibSuff12;
  145. {
  146. * Convert time value from human readable format to a numeric apr_time_t
  147. * e.g. elapsed usec since epoch
  148. * @param result the resulting imploded time
  149. * @param input the input exploded time
  150. }
  151. function apr_time_exp_get(result: Papr_time_t;
  152. input: Papr_time_exp_t): apr_status_t;
  153. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  154. external LibAPR name LibNamePrefix + 'apr_time_exp_get' + LibSuff8;
  155. {
  156. * Convert time value from human readable format to a numeric apr_time_t that
  157. * always represents GMT
  158. * @param result the resulting imploded time
  159. * @param input the input exploded time
  160. }
  161. function apr_time_exp_gmt_get(result: Papr_time_t;
  162. input: Papr_time_exp_t): apr_status_t;
  163. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  164. external LibAPR name LibNamePrefix + 'apr_time_exp_gmt_get' + LibSuff8;
  165. { @deprecated @see apr_time_exp_gmt_get }
  166. function apr_implode_gmt(result: Papr_time_t;
  167. input: Papr_time_exp_t): apr_status_t;
  168. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  169. external LibAPR name LibNamePrefix + 'apr_implode_gmt' + LibSuff8;
  170. {
  171. * Sleep for the specified number of micro-seconds.
  172. * @param t desired amount of time to sleep.
  173. * @warning May sleep for longer than the specified time.
  174. }
  175. procedure apr_sleep(t: apr_interval_time_t);
  176. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  177. external LibAPR name LibNamePrefix + 'apr_sleep' + LibSuff8;
  178. { length of a RFC822 Date }
  179. const APR_RFC822_DATE_LEN = (30);
  180. {
  181. * apr_rfc822_date formats dates in the RFC822
  182. * format in an efficient manner. It is a fixed length
  183. * format which requires the indicated amount of storage,
  184. * including the trailing null byte.
  185. * @param date_str String to write to.
  186. * @param t the time to convert
  187. }
  188. function apr_rfc822_date(date_str: PChar; t: apr_time_t): apr_status_t;
  189. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  190. external LibAPR name LibNamePrefix + 'apr_rfc822_date' + LibSuff12;
  191. { length of a CTIME date }
  192. const APR_CTIME_LEN = (25);
  193. {
  194. * apr_ctime formats dates in the ctime() format
  195. * in an efficient manner. it is a fixed length format
  196. * and requires the indicated amount of storage including
  197. * the trailing null byte.
  198. * Unlike ANSI/ISO C ctime(), apr_ctime() does not include
  199. * a \n at the end of the string.
  200. * @param date_str String to write to.
  201. * @param t the time to convert
  202. }
  203. function apr_ctime(date_str: PChar; t: apr_time_t): apr_status_t;
  204. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  205. external LibAPR name LibNamePrefix + 'apr_ctime' + LibSuff12;
  206. {
  207. * formats the exploded time according to the format specified
  208. * @param s string to write to
  209. * @param retsize The length of the returned string
  210. * @param max The maximum length of the string
  211. * @param format The format for the time string
  212. * @param tm The time to convert
  213. }
  214. function apr_strftime(s: PChar; retsize: apr_size_t;
  215. max: apr_size_t; const format: PChar;
  216. tm: Papr_time_exp_t): apr_status_t;
  217. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  218. external LibAPR name LibNamePrefix + 'apr_strftime' + LibSuff20;
  219. {
  220. * Improve the clock resolution for the lifetime of the given pool.
  221. * Generally this is only desireable on benchmarking and other very
  222. * time-sensitive applications, and has no impact on most platforms.
  223. * @param p The pool to associate the finer clock resolution
  224. }
  225. procedure apr_time_clock_hires(p: Papr_pool_t);
  226. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  227. external LibAPR name LibNamePrefix + 'apr_time_clock_hires' + LibSuff4;