Add time and realtime clock functions
Adds functions to query the system's realtime clock, convert time intervals to/from a calendar date and time in either UTC or the local time, and perform time related calculations. An SDL_Time type (a time interval represented in nanoseconds), and SDL_DateTime struct (broken down calendar date and time) were added to facilitate this functionality. Querying the system time results in a value expressed in nanoseconds since the Unix epoch (Jan 1, 1970) in UTC +0000. Conversions to and from the various platform epochs and units are performed when required. Any direct handling of timezones and DST were intentionally avoided. The offset from UTC is provided when converting from UTC to a local time by calculating the difference between the original UTC and the resulting local time, but no other timezone or DST information is used. The preferred date formatting and 12/24 hour time for the system locale can be retrieved via global preferences. Helper functions for obtaining the day of week or day or year for calendar date, and getting the number of days in a month in a given year are provided for convenience. These are simple, but useful for performing various time related calculations. An automated test for time conversion is included, as is a simple standalone test to display the current system date and time onscreen along with a calendar, the rendering of which demonstrates the use of the utility functions (press up/down to increment or decrement the current month, and keys 1-5 to change the date and time formats).
This commit is contained in:
parent
b6c9a72740
commit
a6fbf0488c
41 changed files with 1862 additions and 78 deletions
|
@ -245,19 +245,13 @@ typedef enum SDL_PathType
|
|||
SDL_PATHTYPE_OTHER /**< something completely different like a device node (not a symlink, those are always followed) */
|
||||
} SDL_PathType;
|
||||
|
||||
/* SDL file times are 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970)
|
||||
*
|
||||
* They can be converted between to POSIX time_t values with SDL_NS_TO_SECONDS() and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with SDL_FileTimeToWindows() and SDL_FileTimeFromWindows()
|
||||
*/
|
||||
typedef Sint64 SDL_FileTime;
|
||||
|
||||
typedef struct SDL_PathInfo
|
||||
{
|
||||
SDL_PathType type; /* the path type */
|
||||
Uint64 size; /* the file size in bytes */
|
||||
SDL_FileTime create_time; /* the time when the path was created */
|
||||
SDL_FileTime modify_time; /* the last time the path was modified */
|
||||
SDL_FileTime access_time; /* the last time the path was read */
|
||||
SDL_Time create_time; /* the time when the path was created */
|
||||
SDL_Time modify_time; /* the last time the path was modified */
|
||||
SDL_Time access_time; /* the last time the path was read */
|
||||
} SDL_PathInfo;
|
||||
|
||||
/**
|
||||
|
@ -323,30 +317,6 @@ extern DECLSPEC int SDLCALL SDL_RenamePath(const char *oldpath, const char *newp
|
|||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info);
|
||||
|
||||
/* Converts an SDL file time into a Windows FILETIME (100-nanosecond intervals since January 1, 1601).
|
||||
*
|
||||
* This function fills in the two 32-bit values of the FILETIME structure.
|
||||
*
|
||||
* \param ftime the time to convert
|
||||
* \param dwLowDateTime a pointer filled in with the low portion of the Windows FILETIME value
|
||||
* \param dwHighDateTime a pointer filled in with the high portion of the Windows FILETIME value
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*/
|
||||
extern DECLSPEC void SDLCALL SDL_FileTimeToWindows(SDL_FileTime ftime, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
|
||||
|
||||
/* Converts a Windows FILETIME (100-nanosecond intervals since January 1, 1601) to an SDL file time
|
||||
*
|
||||
* This function takes the two 32-bit values of the FILETIME structure as parameters.
|
||||
*
|
||||
* \param dwLowDateTime the low portion of the Windows FILETIME value
|
||||
* \param dwHighDateTime the high portion of the Windows FILETIME value
|
||||
* \returns the converted file time
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*/
|
||||
extern DECLSPEC SDL_FileTime SDLCALL SDL_FileTimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue