|
| 1 | +{ |
| 2 | + This file is part of: |
| 3 | +
|
| 4 | + SDL3 for Pascal |
| 5 | + (https://github.com/PascalGameDevelopment/SDL3-for-Pascal) |
| 6 | + SPDX-License-Identifier: Zlib |
| 7 | +} |
| 8 | + |
| 9 | +{* |
| 10 | + * # CategoryTime |
| 11 | + * |
| 12 | + * SDL realtime clock and date/time routines. |
| 13 | + * |
| 14 | + * There are two data types that are used in this category: SDL_Time, which |
| 15 | + * represents the nanoseconds since a specific moment (an "epoch"), and |
| 16 | + * SDL_DateTime, which breaks time down into human-understandable components: |
| 17 | + * years, months, days, hours, etc. |
| 18 | + * |
| 19 | + * Much of the functionality is involved in converting those two types to |
| 20 | + * other useful forms. |
| 21 | + } |
| 22 | +{* |
| 23 | + * A structure holding a calendar date and time broken down into its |
| 24 | + * components. |
| 25 | + * |
| 26 | + * \since This struct is available since SDL 3.2.0. |
| 27 | + } |
| 28 | +type |
| 29 | + PPSDL_DateTime = ^PSDL_DateTime; |
| 30 | + PSDL_DateTime = ^TSDL_DateTime; |
| 31 | + TSDL_DateTime = record |
| 32 | + year: cint; {*< Year } |
| 33 | + month: cint; {*< Month [01-12] } |
| 34 | + day: cint; {*< Day of the month [01-31] } |
| 35 | + hour: cint; {*< Hour [0-23] } |
| 36 | + minute: cint; {*< Minute [0-59] } |
| 37 | + second: cint; {*< Seconds [0-60] } |
| 38 | + nanosecond: cint; {*< Nanoseconds [0-999999999] } |
| 39 | + day_of_week: cint; {*< Day of the week [0-6] (0 being Sunday) } |
| 40 | + utc_offset: cint; {*< Seconds east of UTC } |
| 41 | + end; |
| 42 | + |
| 43 | +{* |
| 44 | + * The preferred date format of the current system locale. |
| 45 | + * |
| 46 | + * \since This enum is available since SDL 3.2.0. |
| 47 | + * |
| 48 | + * \sa SDL_GetDateTimeLocalePreferences |
| 49 | + } |
| 50 | +type |
| 51 | + PPSDL_DateFormat = ^PSDL_DateFormat; |
| 52 | + PSDL_DateFormat = ^TSDL_DateFormat; |
| 53 | + TSDL_DateFormat = type Integer; |
| 54 | +const |
| 55 | + SDL_DATE_FORMAT_YYYYMMDD = TSDL_DateFormat(0); {*< Year/Month/Day } |
| 56 | + SDL_DATE_FORMAT_DDMMYYYY = TSDL_DateFormat(1); {*< Day/Month/Year } |
| 57 | + SDL_DATE_FORMAT_MMDDYYYY = TSDL_DateFormat(2); {*< Month/Day/Year } |
| 58 | + |
| 59 | +{* |
| 60 | + * The preferred time format of the current system locale. |
| 61 | + * |
| 62 | + * \since This enum is available since SDL 3.2.0. |
| 63 | + * |
| 64 | + * \sa SDL_GetDateTimeLocalePreferences |
| 65 | + } |
| 66 | +type |
| 67 | + PPSDL_TimeFormat = ^PSDL_TimeFormat; |
| 68 | + PSDL_TimeFormat = ^TSDL_TimeFormat; |
| 69 | + TSDL_TimeFormat = type Integer; |
| 70 | +const |
| 71 | + SDL_TIME_FORMAT_24HR = TSDL_TimeFormat(0); {*< 24 hour time } |
| 72 | + SDL_TIME_FORMAT_12HR = TSDL_TimeFormat(1); {*< 12 hour time } |
| 73 | + |
| 74 | +{* |
| 75 | + * Gets the current preferred date and time format for the system locale. |
| 76 | + * |
| 77 | + * This might be a "slow" call that has to query the operating system. It's |
| 78 | + * best to ask for this once and save the results. However, the preferred |
| 79 | + * formats can change, usually because the user has changed a system |
| 80 | + * preference outside of your program. |
| 81 | + * |
| 82 | + * \param dateFormat a Pointer to the SDL_DateFormat to hold the returned date |
| 83 | + * format, may be nil. |
| 84 | + * \param timeFormat a Pointer to the SDL_TimeFormat to hold the returned time |
| 85 | + * format, may be nil. |
| 86 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 87 | + * information. |
| 88 | + * |
| 89 | + * \since This function is available since SDL 3.2.0. |
| 90 | + } |
| 91 | +function SDL_GetDateTimeLocalePreferences(dateFormat: PSDL_DateFormat; timeFormat: PSDL_TimeFormat): cbool; cdecl; |
| 92 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDateTimeLocalePreferences' {$ENDIF} {$ENDIF}; |
| 93 | + |
| 94 | +{* |
| 95 | + * Gets the current value of the system realtime clock in nanoseconds since |
| 96 | + * Jan 1, 1970 in Universal Coordinated Time (UTC). |
| 97 | + * |
| 98 | + * \param ticks the SDL_Time to hold the returned tick count. |
| 99 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 100 | + * information. |
| 101 | + * |
| 102 | + * \since This function is available since SDL 3.2.0. |
| 103 | + } |
| 104 | +function SDL_GetCurrentTime(ticks: PSDL_Time): cbool; cdecl; |
| 105 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCurrentTime' {$ENDIF} {$ENDIF}; |
| 106 | + |
| 107 | +{* |
| 108 | + * Converts an SDL_Time in nanoseconds since the epoch to a calendar time in |
| 109 | + * the SDL_DateTime format. |
| 110 | + * |
| 111 | + * \param ticks the SDL_Time to be converted. |
| 112 | + * \param dt the resulting SDL_DateTime. |
| 113 | + * \param localTime the resulting SDL_DateTime will be expressed in local time |
| 114 | + * if true, otherwise it will be in Universal Coordinated |
| 115 | + * Time (UTC). |
| 116 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 117 | + * information. |
| 118 | + * |
| 119 | + * \since This function is available since SDL 3.2.0. |
| 120 | + } |
| 121 | +function SDL_TimeToDateTime(ticks: TSDL_Time; dt: PSDL_DateTime; localTime: cbool): cbool; cdecl; |
| 122 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeToDateTime' {$ENDIF} {$ENDIF}; |
| 123 | + |
| 124 | +{* |
| 125 | + * Converts a calendar time to an SDL_Time in nanoseconds since the epoch. |
| 126 | + * |
| 127 | + * This function ignores the day_of_week member of the SDL_DateTime struct, so |
| 128 | + * it may remain unset. |
| 129 | + * |
| 130 | + * \param dt the source SDL_DateTime. |
| 131 | + * \param ticks the resulting SDL_Time. |
| 132 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 133 | + * information. |
| 134 | + * |
| 135 | + * \since This function is available since SDL 3.2.0. |
| 136 | + } |
| 137 | +function SDL_DateTimeToTime(dt: PSDL_DateTime; ticks: PSDL_Time): cbool; cdecl; |
| 138 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_DateTimeToTime' {$ENDIF} {$ENDIF}; |
| 139 | + |
| 140 | +{* |
| 141 | + * Converts an SDL time into a Windows FILETIME (100-nanosecond intervals |
| 142 | + * since January 1, 1601). |
| 143 | + * |
| 144 | + * This function fills in the two 32-bit values of the FILETIME structure. |
| 145 | + * |
| 146 | + * \param ticks the time to convert. |
| 147 | + * \param dwLowDateTime a Pointer filled in with the low portion of the |
| 148 | + * Windows FILETIME value. |
| 149 | + * \param dwHighDateTime a Pointer filled in with the high portion of the |
| 150 | + * Windows FILETIME value. |
| 151 | + * |
| 152 | + * \since This function is available since SDL 3.2.0. |
| 153 | + } |
| 154 | +procedure SDL_TimeToWindows(ticks: TSDL_Time; dwLowDateTime: pcuint32; dwHighDateTime: pcuint32); cdecl; |
| 155 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeToWindows' {$ENDIF} {$ENDIF}; |
| 156 | + |
| 157 | +{* |
| 158 | + * Converts a Windows FILETIME (100-nanosecond intervals since January 1, |
| 159 | + * 1601) to an SDL time. |
| 160 | + * |
| 161 | + * This function takes the two 32-bit values of the FILETIME structure as |
| 162 | + * parameters. |
| 163 | + * |
| 164 | + * \param dwLowDateTime the low portion of the Windows FILETIME value. |
| 165 | + * \param dwHighDateTime the high portion of the Windows FILETIME value. |
| 166 | + * \returns the converted SDL time. |
| 167 | + * |
| 168 | + * \since This function is available since SDL 3.2.0. |
| 169 | + } |
| 170 | +function SDL_TimeFromWindows(dwLowDateTime: cuint32; dwHighDateTime: cuint32): TSDL_Time; cdecl; |
| 171 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_TimeFromWindows' {$ENDIF} {$ENDIF}; |
| 172 | + |
| 173 | +{* |
| 174 | + * Get the number of days in a month for a given year. |
| 175 | + * |
| 176 | + * \param year the year. |
| 177 | + * \param month the month [1-12]. |
| 178 | + * \returns the number of days in the requested month or -1 on failure; call |
| 179 | + * SDL_GetError() for more information. |
| 180 | + * |
| 181 | + * \since This function is available since SDL 3.2.0. |
| 182 | + } |
| 183 | +function SDL_GetDaysInMonth(year: cint; month: cint): cint; cdecl; |
| 184 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDaysInMonth' {$ENDIF} {$ENDIF}; |
| 185 | + |
| 186 | +{* |
| 187 | + * Get the day of year for a calendar date. |
| 188 | + * |
| 189 | + * \param year the year component of the date. |
| 190 | + * \param month the month component of the date. |
| 191 | + * \param day the day component of the date. |
| 192 | + * \returns the day of year [0-365] if the date is valid or -1 on failure; |
| 193 | + * call SDL_GetError() for more information. |
| 194 | + * |
| 195 | + * \since This function is available since SDL 3.2.0. |
| 196 | + } |
| 197 | +function SDL_GetDayOfYear(year: cint; month: cint; day: cint): cint; cdecl; |
| 198 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDayOfYear' {$ENDIF} {$ENDIF}; |
| 199 | + |
| 200 | +{* |
| 201 | + * Get the day of week for a calendar date. |
| 202 | + * |
| 203 | + * \param year the year component of the date. |
| 204 | + * \param month the month component of the date. |
| 205 | + * \param day the day component of the date. |
| 206 | + * \returns a value between 0 and 6 (0 being Sunday) if the date is valid or |
| 207 | + * -1 on failure; call SDL_GetError() for more information. |
| 208 | + * |
| 209 | + * \since This function is available since SDL 3.2.0. |
| 210 | + } |
| 211 | +function SDL_GetDayOfWeek(year: cint; month: cint; day: cint): cint; cdecl; |
| 212 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetDayOfWeek' {$ENDIF} {$ENDIF}; |
| 213 | + |
0 commit comments