gmtdate.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2003 Intel Corporation
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above copyright notice,
  12. // this list of conditions and the following disclaimer in the documentation
  13. // and/or other materials provided with the distribution.
  14. // * Neither name of Intel Corporation nor the names of its contributors
  15. // may be used to endorse or promote products derived from this software
  16. // without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  22. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  26. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. ///////////////////////////////////////////////////////////////////////////
  31. #ifndef GENLIB_UTIL_GMTDATE_H
  32. #define GENLIB_UTIL_GMTDATE_H
  33. #include <time.h>
  34. #include <genlib/util/util.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. // input: monthStr: 3-letter or full month
  39. // returns month=0..11 or -1 on failure
  40. // output:
  41. // charsRead - num chars that match the month
  42. // fullNameMatch - full name match(1) or 3-letter match(0)
  43. //
  44. int ParseMonth( IN const char* monthStr,
  45. OUT int* charsRead, OUT int* fullNameMatch );
  46. // input: dayOfWeek: 3-letter or full day of week ("mon" etc)
  47. // returns dayOfWeek=0..6 or -1 on failure
  48. // output:
  49. // charsRead - num chars that match the month
  50. // fullNameMatch - full name match(1) or 3-letter match(0)
  51. //
  52. int ParseDayOfWeek( IN const char* dayOfWeek,
  53. OUT int* charsRead, OUT int* fullNameMatch );
  54. // converts date to string format: RFC 1123 format:
  55. // Sun, 06 Nov 1994 08:49:37 GMT
  56. // String returned must be freed using free() function
  57. // returns NULL if date is NULL
  58. //
  59. // throws OutOfMemoryException
  60. char* DateToString( const struct tm* date );
  61. // parses time in fmt hh:mm:ss, military fmt
  62. // returns 0 on success; -1 on error
  63. int ParseTime( const char* s, int* hour, int* minute, int* second );
  64. // tries to parse date according to RFCs 1123, 850, or asctime()
  65. // format
  66. // params:
  67. // str - contains date/time in string format
  68. // dateTime - date and time obtained from 'str'
  69. // returns: 0 on success, -1 on error
  70. int ParseRFC850DateTime( IN const char* str,
  71. OUT struct tm* dateTime, OUT int* numCharsParsed );
  72. int ParseRFC1123DateTime( IN const char* str,
  73. OUT struct tm* dateTime, OUT int* numCharsParsed );
  74. int ParseAsctimeFmt( IN const char* str,
  75. OUT struct tm* dateTime, OUT int* numCharsParsed );
  76. // parses any of these formats: 1123, 850 or asctime()
  77. int ParseDateTime( IN const char* str,
  78. OUT struct tm* dateTime, OUT int* numCharsParsed );
  79. #ifdef __cplusplus
  80. } /* extern C */
  81. #endif
  82. #endif /* GENLIB_UTIL_GMTDATE_H */