21
#include "SDL_internal.h"
27
#include <psputility_sysparam.h>
29
#include "../SDL_time_c.h"
32
#define DELTA_EPOCH_0001_OFFSET 62135596800ULL
34
void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
38
if (df && sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_DATE_FORMAT, &val) == 0) {
40
case PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD:
41
*df = SDL_DATE_FORMAT_YYYYMMDD;
43
case PSP_SYSTEMPARAM_DATE_FORMAT_MMDDYYYY:
44
*df = SDL_DATE_FORMAT_MMDDYYYY;
46
case PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY:
47
*df = SDL_DATE_FORMAT_DDMMYYYY;
54
if (tf && sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_TIME_FORMAT, &val) == 0) {
56
case PSP_SYSTEMPARAM_TIME_FORMAT_24HR:
57
*tf = SDL_TIME_FORMAT_24HR;
59
case PSP_SYSTEMPARAM_TIME_FORMAT_12HR:
60
*tf = SDL_TIME_FORMAT_12HR;
68
SDL_bool SDL_GetCurrentTime(SDL_Time *ticks)
73
return SDL_InvalidParamError("ticks");
76
const int ret = sceRtcGetCurrentTick(&sceTicks);
78
const u32 res = sceRtcGetTickResolution();
79
const u32 div = SDL_NS_PER_SECOND / res;
80
const Uint64 epoch_offset = DELTA_EPOCH_0001_OFFSET * res;
82
const Uint64 scetime_min = (Uint64)((SDL_MIN_TIME / div) + epoch_offset);
83
const Uint64 scetime_max = (Uint64)((SDL_MAX_TIME / div) + epoch_offset);
86
sceTicks = SDL_clamp(sceTicks, scetime_min, scetime_max);
88
*ticks = (SDL_Time)(sceTicks - epoch_offset) * div;
93
return SDL_SetError("Failed to retrieve system time (%i)", ret);
96
SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime)
103
return SDL_InvalidParamError("dt");
106
const u32 res = sceRtcGetTickResolution();
107
const u32 div = (SDL_NS_PER_SECOND / res);
108
const u64 sceTicks = (u64)((ticks / div) + (DELTA_EPOCH_0001_OFFSET * div));
111
ret = sceRtcConvertUtcToLocalTime(&sceTicks, &local);
117
ret = sceRtcSetTick(&t, &local);
123
dt->minute = t.minute;
124
dt->second = t.second;
125
dt->nanosecond = ticks % SDL_NS_PER_SECOND;
126
dt->utc_offset = (int)(((Sint64)local - (Sint64)sceTicks) / (Sint64)res);
128
SDL_CivilToDays(dt->year, dt->month, dt->day, &dt->day_of_week, NULL);
134
return SDL_SetError("Local time conversion failed (%i)", ret);