SDL_time.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_time_h_
  19. #define SDL_time_h_
  20. /**
  21. * \file SDL_time.h
  22. *
  23. * Header for the SDL realtime clock and date/time routines.
  24. */
  25. #include <SDL3/SDL_error.h>
  26. #include <SDL3/SDL_stdinc.h>
  27. #include <SDL3/SDL_begin_code.h>
  28. /* Set up for C function definitions, even when using C++ */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * A structure holding a calendar date and time broken down into its components.
  34. */
  35. typedef struct SDL_DateTime
  36. {
  37. int year; /**< Year */
  38. int month; /**< Month [01-12] */
  39. int day; /**< Day of the month [01-31] */
  40. int hour; /**< Hour [0-23] */
  41. int minute; /**< Minute [0-59] */
  42. int second; /**< Seconds [0-60] */
  43. int nanosecond; /**< Nanoseconds [0-999999999] */
  44. int day_of_week; /**< Day of the week [0-6] (0 being Sunday) */
  45. int utc_offset; /**< Seconds east of UTC */
  46. } SDL_DateTime;
  47. /**
  48. * The preferred date format of the current system locale.
  49. *
  50. * \sa SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER
  51. */
  52. typedef enum SDL_DATE_FORMAT
  53. {
  54. SDL_DATE_FORMAT_YYYYMMDD = 0, /**< Year/Month/Day */
  55. SDL_DATE_FORMAT_DDMMYYYY = 1, /**< Day/Month/Year */
  56. SDL_DATE_FORMAT_MMDDYYYY = 2, /**< Month/Day/Year */
  57. } SDL_DATE_FORMAT;
  58. /**
  59. * The preferred time format of the current system locale.
  60. *
  61. * \sa SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER
  62. */
  63. typedef enum SDL_TIME_FORMAT
  64. {
  65. SDL_TIME_FORMAT_24HR = 0, /**< 24 hour time */
  66. SDL_TIME_FORMAT_12HR = 1, /**< 12 hour time */
  67. } SDL_TIME_FORMAT;
  68. /**
  69. * Global date/time properties
  70. *
  71. * - `SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER`: the SDL_DATE_FORMAT to use as the preferred date display format
  72. * for the current system locale.
  73. * - `SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER`: the SDL_TIME_FORMAT to use as the preferred time display format
  74. * for the current system locale.
  75. */
  76. #define SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER "SDL.time.date_format"
  77. #define SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER "SDL.time.time_format"
  78. /**
  79. * Gets the current value of the system realtime clock in nanoseconds since Jan 1, 1970 in
  80. * Universal Coordinated Time (UTC).
  81. *
  82. * \param ticks the SDL_Time to hold the returned tick count
  83. * \returns 0 on success or -1 on error; call SDL_GetError() for more information.
  84. *
  85. * \since This function is available since SDL 3.0.0
  86. */
  87. extern DECLSPEC int SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
  88. /**
  89. * Converts an SDL_Time in nanoseconds since the epoch to a calendar time in the SDL_DateTime format.
  90. *
  91. * \param ticks the SDL_Time to be converted
  92. * \param dt the resulting SDL_DateTime
  93. * \param localTime the resulting SDL_DateTime will be expressed in local time if true, otherwise
  94. * it will be in Universal Coordinated Time (UTC)
  95. * \returns 0 on success or -1 on error; call SDL_GetError() for more information.
  96. *
  97. * \since This function is available since SDL 3.0.0
  98. */
  99. extern DECLSPEC int SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime);
  100. /**
  101. * Converts a calendar time to an SDL_Time in nanoseconds since the epoch.
  102. * This function ignores the day_of_week member of the SDL_DateTime struct, so it may remain unset.
  103. *
  104. * \param dt the source SDL_DateTime
  105. * \param ticks the resulting SDL_Time
  106. * \returns 0 on success or -1 on error; call SDL_GetError() for more information.
  107. *
  108. * \since This function is available since SDL 3.0.0
  109. */
  110. extern DECLSPEC int SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks);
  111. /**
  112. * Converts an SDL time into a Windows FILETIME (100-nanosecond intervals since January 1, 1601).
  113. *
  114. * This function fills in the two 32-bit values of the FILETIME structure.
  115. *
  116. * \param ticks the time to convert
  117. * \param dwLowDateTime a pointer filled in with the low portion of the Windows FILETIME value
  118. * \param dwHighDateTime a pointer filled in with the high portion of the Windows FILETIME value
  119. *
  120. * \since This function is available since SDL 3.0.0.
  121. */
  122. extern DECLSPEC void SDLCALL SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
  123. /**
  124. * Converts a Windows FILETIME (100-nanosecond intervals since January 1, 1601) to an SDL time
  125. *
  126. * This function takes the two 32-bit values of the FILETIME structure as parameters.
  127. *
  128. * \param dwLowDateTime the low portion of the Windows FILETIME value
  129. * \param dwHighDateTime the high portion of the Windows FILETIME value
  130. * \returns the converted SDL time
  131. *
  132. * \since This function is available since SDL 3.0.0.
  133. */
  134. extern DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
  135. /**
  136. * Get the number of days in a month for a given year.
  137. *
  138. * \param year the year
  139. * \param month the month [1-12]
  140. * \returns the number of days in the requested month, otherwise -1; call SDL_GetError() for more information.
  141. *
  142. * \since This function is available since SDL 3.0.0
  143. */
  144. extern DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month);
  145. /**
  146. * Get the day of year for a calendar date.
  147. *
  148. * \param year the year component of the date
  149. * \param month the month component of the date
  150. * \param day the day component of the date
  151. * \returns the day of year [0-365] if the date is valid, otherwise -1; call SDL_GetError()
  152. * for more information.
  153. *
  154. * \since This function is available since SDL 3.0.0
  155. */
  156. extern DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day);
  157. /**
  158. * Get the day of week for a calendar date.
  159. *
  160. * \param year the year component of the date
  161. * \param month the month component of the date
  162. * \param day the day component of the date
  163. * \returns a value between 0 and 6 (0 being Sunday) if the date is valid, otherwise -1; call SDL_GetError()
  164. * for more information.
  165. *
  166. * \since This function is available since SDL 3.0.0
  167. */
  168. extern DECLSPEC int SDLCALL SDL_GetDayOfWeek(int year, int month, int day);
  169. /* Ends C function definitions when using C++ */
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #include <SDL3/SDL_close_code.h>
  174. #endif /* SDL_time_h_ */