time.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef __TIME_H
  2. #define __TIME_H
  3. /*
  4. * Copyright (C) 2001-2003 by egnite Software GmbH. 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
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. /*
  36. * $Log$
  37. * Revision 1.9 2009/03/05 22:51:14 freckle
  38. * revert change and define time_t on __linux__
  39. *
  40. * Revision 1.8 2009/03/05 22:16:57 freckle
  41. * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__
  42. *
  43. * Revision 1.7 2008/08/11 06:59:58 haraldkipp
  44. * BSD types replaced by stdint types (feature request #1282721).
  45. *
  46. * Revision 1.6 2005/01/19 17:03:35 freckle
  47. * forget to check in other cygwin fixes
  48. *
  49. * Revision 1.5 2004/04/07 12:13:57 haraldkipp
  50. * Matthias Ringwald's *nix emulation added
  51. *
  52. * Revision 1.4 2004/03/16 16:48:27 haraldkipp
  53. * Added Jan Dubiec's H8/300 port.
  54. *
  55. * Revision 1.3 2003/12/19 22:24:25 drsung
  56. * Dox written.
  57. *
  58. * Revision 1.2 2003/11/26 11:15:34 haraldkipp
  59. * Portability issues
  60. *
  61. * Revision 1.1 2003/11/24 18:11:03 drsung
  62. * first release
  63. *
  64. *
  65. */
  66. /*!
  67. * \file time.h
  68. * \brief Standard C time handling functions.
  69. */
  70. #include <compiler.h>
  71. #include <sys/types.h>
  72. /*!
  73. * \addtogroup xgCrtTime
  74. * @{
  75. */
  76. /*!
  77. * \brief Type definition for struct _tm
  78. */
  79. typedef struct _tm tm;
  80. /*!
  81. * \brief structure to store a date/time value.
  82. *
  83. * The structure tm stores a complete date and time combination. The granularity
  84. * is one second.
  85. *
  86. * \note The range of \b tm_mon is from 0 (January) to 11 (December).\n
  87. * \b tm_year holds the year since 1900, for example value 103 means year 2003.
  88. */
  89. struct _tm {
  90. int tm_sec; /*!< \brief seconds after the minute - [0,59] */
  91. int tm_min; /*!< \brief minutes after the hour - [0,59] */
  92. int tm_hour; /*!< \brief hours since midnight - [0,23] */
  93. int tm_mday; /*!< \brief day of the month - [1,31] */
  94. int tm_mon; /*!< \brief months since January - [0,11] */
  95. int tm_year; /*!< \brief years since 1900 */
  96. int tm_wday; /*!< \brief days since Sunday - [0,6] */
  97. int tm_yday; /*!< \brief days since January 1 - [0,365] */
  98. int tm_isdst; /*!< \brief daylight savings time flag */
  99. };
  100. /*!
  101. * \typedef long time_t
  102. * \brief Serial date/time. Holds number of seconds after January 1st, 1970.
  103. */
  104. // time_t is defind on __APPLE__ and __CYGWIN, but not on __linux__ or on embedded systems
  105. #if !defined(__APPLE__) && !defined(__CYGWIN__)
  106. typedef long time_t;
  107. #endif
  108. char *asctime_r(const struct _tm *timep, char *buf);
  109. char *asctime(register const struct _tm *timep);
  110. char *ctime(const time_t *timep);
  111. char *ctime_r(const time_t *timep, char *buf);
  112. int gmtime_r(const time_t * timer, tm * theTime);
  113. tm *gmtime(const time_t * timer);
  114. int localtime_r(const time_t * timer, tm * theTime);
  115. tm *localtime(const time_t * timer);
  116. time_t time(time_t * timer);
  117. int stime(time_t * timer);
  118. time_t mktime(tm * timeptr);
  119. time_t _mkgmtime(tm * timeptr);
  120. /*!
  121. * \brief Offset of the system time compared to epoc
  122. *
  123. * Used to calculate current time from the system run-time.
  124. */
  125. extern struct timeval epo_offs;
  126. /*!
  127. * \brief Used to control daylight conversions.
  128. *
  129. * Assign a nonzero value to enable daylight conversions. If enabled
  130. * the hour part of time values is adjusted if we are in daylight saving time.
  131. * Zero value to disable conversion.
  132. * Default is enabled.
  133. */
  134. extern int _daylight;
  135. /*!
  136. * \brief Defines your local timezone.
  137. *
  138. * Difference in seconds between universal coordinated time and local time.
  139. * This value is subtracted from the universal coordinated time to
  140. * calculate your local time. Default value is 5 * 60 * 60 = 18000,
  141. * which defines the time zone EST (GMT-5).
  142. *
  143. * \note Before using the time functions, set \b _timezone to your
  144. * local value.
  145. *
  146. */
  147. extern long _timezone;
  148. /*!
  149. * \brief Difference between standard and daylight savings time in seconds.
  150. *
  151. * This value is used to calculate the daylight savings time by subtracting this
  152. * value from the standard time. Unit is seconds.
  153. * Usually daylight savings time is one hour in advance to standard time, thus the default
  154. * value is -1 * 60 * 60 = -3600.
  155. */
  156. extern long _dstbias;
  157. /*@}*/
  158. #endif