SDL_time.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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
  34. * components.
  35. *
  36. * \since This struct is available since SDL 3.0.0.
  37. */
  38. typedef struct SDL_DateTime
  39. {
  40. int year; /**< Year */
  41. int month; /**< Month [01-12] */
  42. int day; /**< Day of the month [01-31] */
  43. int hour; /**< Hour [0-23] */
  44. int minute; /**< Minute [0-59] */
  45. int second; /**< Seconds [0-60] */
  46. int nanosecond; /**< Nanoseconds [0-999999999] */
  47. int day_of_week; /**< Day of the week [0-6] (0 being Sunday) */
  48. int utc_offset; /**< Seconds east of UTC */
  49. } SDL_DateTime;
  50. /**
  51. * The preferred date format of the current system locale.
  52. *
  53. * \since This enum is available since SDL 3.0.0.
  54. *
  55. * \sa SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER
  56. */
  57. typedef enum SDL_DateFormat
  58. {
  59. SDL_DATE_FORMAT_YYYYMMDD = 0, /**< Year/Month/Day */
  60. SDL_DATE_FORMAT_DDMMYYYY = 1, /**< Day/Month/Year */
  61. SDL_DATE_FORMAT_MMDDYYYY = 2 /**< Month/Day/Year */
  62. } SDL_DateFormat;
  63. /**
  64. * The preferred time format of the current system locale.
  65. *
  66. * \since This enum is available since SDL 3.0.0.
  67. *
  68. * \sa SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER
  69. */
  70. typedef enum SDL_TimeFormat
  71. {
  72. SDL_TIME_FORMAT_24HR = 0, /**< 24 hour time */
  73. SDL_TIME_FORMAT_12HR = 1 /**< 12 hour time */
  74. } SDL_TimeFormat;
  75. /*
  76. * Global date/time properties.
  77. *
  78. * - `SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER`: the SDL_DateFormat to use as the preferred date display format
  79. * for the current system locale.
  80. * - `SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER`: the SDL_TimeFormat to use as the preferred time display format
  81. * for the current system locale.
  82. */
  83. #define SDL_PROP_GLOBAL_SYSTEM_DATE_FORMAT_NUMBER "SDL.time.date_format"
  84. #define SDL_PROP_GLOBAL_SYSTEM_TIME_FORMAT_NUMBER "SDL.time.time_format"
  85. /**
  86. * Gets the current value of the system realtime clock in nanoseconds since
  87. * Jan 1, 1970 in Universal Coordinated Time (UTC).
  88. *
  89. * \param ticks the SDL_Time to hold the returned tick count
  90. * \returns 0 on success or -1 on error; call SDL_GetError() for more
  91. * information.
  92. *
  93. * \since This function is available since SDL 3.0.0.
  94. */
  95. extern DECLSPEC int SDLCALL SDL_GetCurrentTime(SDL_Time *ticks);
  96. /**
  97. * Converts an SDL_Time in nanoseconds since the epoch to a calendar time in
  98. * the SDL_DateTime format.
  99. *
  100. * \param ticks the SDL_Time to be converted
  101. * \param dt the resulting SDL_DateTime
  102. * \param localTime the resulting SDL_DateTime will be expressed in local time
  103. * if true, otherwise it will be in Universal Coordinated
  104. * Time (UTC)
  105. * \returns 0 on success or -1 on error; call SDL_GetError() for more
  106. * information.
  107. *
  108. * \since This function is available since SDL 3.0.0.
  109. */
  110. extern DECLSPEC int SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime);
  111. /**
  112. * Converts a calendar time to an SDL_Time in nanoseconds since the epoch.
  113. *
  114. * This function ignores the day_of_week member of the SDL_DateTime struct, so
  115. * it may remain unset.
  116. *
  117. * \param dt the source SDL_DateTime
  118. * \param ticks the resulting SDL_Time
  119. * \returns 0 on success or -1 on error; call SDL_GetError() for more
  120. * information.
  121. *
  122. * \since This function is available since SDL 3.0.0.
  123. */
  124. extern DECLSPEC int SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks);
  125. /**
  126. * Converts an SDL time into a Windows FILETIME (100-nanosecond intervals
  127. * since January 1, 1601).
  128. *
  129. * This function fills in the two 32-bit values of the FILETIME structure.
  130. *
  131. * \param ticks the time to convert
  132. * \param dwLowDateTime a pointer filled in with the low portion of the
  133. * Windows FILETIME value
  134. * \param dwHighDateTime a pointer filled in with the high portion of the
  135. * Windows FILETIME value
  136. *
  137. * \since This function is available since SDL 3.0.0.
  138. */
  139. extern DECLSPEC void SDLCALL SDL_TimeToWindows(SDL_Time ticks, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
  140. /**
  141. * Converts a Windows FILETIME (100-nanosecond intervals since January 1,
  142. * 1601) to an SDL time.
  143. *
  144. * This function takes the two 32-bit values of the FILETIME structure as
  145. * parameters.
  146. *
  147. * \param dwLowDateTime the low portion of the Windows FILETIME value
  148. * \param dwHighDateTime the high portion of the Windows FILETIME value
  149. * \returns the converted SDL time
  150. *
  151. * \since This function is available since SDL 3.0.0.
  152. */
  153. extern DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
  154. /**
  155. * Get the number of days in a month for a given year.
  156. *
  157. * \param year the year
  158. * \param month the month [1-12]
  159. * \returns the number of days in the requested month, otherwise -1; call
  160. * SDL_GetError() for more information.
  161. *
  162. * \since This function is available since SDL 3.0.0.
  163. */
  164. extern DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month);
  165. /**
  166. * Get the day of year for a calendar date.
  167. *
  168. * \param year the year component of the date
  169. * \param month the month component of the date
  170. * \param day the day component of the date
  171. * \returns the day of year [0-365] if the date is valid, otherwise -1; call
  172. * SDL_GetError() for more information.
  173. *
  174. * \since This function is available since SDL 3.0.0.
  175. */
  176. extern DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day);
  177. /**
  178. * Get the day of week for a calendar date.
  179. *
  180. * \param year the year component of the date
  181. * \param month the month component of the date
  182. * \param day the day component of the date
  183. * \returns a value between 0 and 6 (0 being Sunday) if the date is valid,
  184. * otherwise -1; call SDL_GetError() for more information.
  185. *
  186. * \since This function is available since SDL 3.0.0.
  187. */
  188. extern DECLSPEC int SDLCALL SDL_GetDayOfWeek(int year, int month, int day);
  189. /* Ends C function definitions when using C++ */
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #include <SDL3/SDL_close_code.h>
  194. #endif /* SDL_time_h_ */