21
#include "SDL_internal.h"
25
#include "../SDL_time_c.h"
26
#include <psp2/apputil.h>
28
#include <psp2/system_param.h>
31
#define DELTA_EPOCH_0001_OFFSET 62135596800ULL
33
void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
36
SceAppUtilInitParam initParam;
37
SceAppUtilBootParam bootParam;
40
sceAppUtilInit(&initParam, &bootParam);
42
if (df && sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_DATE_FORMAT, &val) == 0) {
44
case SCE_SYSTEM_PARAM_DATE_FORMAT_YYYYMMDD:
45
*df = SDL_DATE_FORMAT_YYYYMMDD;
47
case SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY:
48
*df = SDL_DATE_FORMAT_MMDDYYYY;
50
case SCE_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY:
51
*df = SDL_DATE_FORMAT_DDMMYYYY;
58
if (tf && sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_DATE_FORMAT, &val) == 0) {
60
case SCE_SYSTEM_PARAM_TIME_FORMAT_24HR:
61
*tf = SDL_TIME_FORMAT_24HR;
63
case SCE_SYSTEM_PARAM_TIME_FORMAT_12HR:
64
*tf = SDL_TIME_FORMAT_12HR;
74
SDL_bool SDL_GetCurrentTime(SDL_Time *ticks)
79
return SDL_InvalidParamError("ticks");
82
const int ret = sceRtcGetCurrentTick(&sceTicks);
84
const unsigned int res = sceRtcGetTickResolution();
85
const unsigned int div = SDL_NS_PER_SECOND / res;
86
const Uint64 epoch_offset = DELTA_EPOCH_0001_OFFSET * res;
88
const Uint64 scetime_min = (Uint64)((SDL_MIN_TIME / div) + epoch_offset);
89
const Uint64 scetime_max = (Uint64)((SDL_MAX_TIME / div) + epoch_offset);
92
sceTicks.tick = SDL_clamp(sceTicks.tick, scetime_min, scetime_max);
93
*ticks = (SDL_Time)(sceTicks.tick - epoch_offset) * div;
98
return SDL_SetError("Failed to retrieve system time (%i)", ret);
101
SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime)
104
SceRtcTick sceTicks, sceLocalTicks;
108
return SDL_InvalidParamError("dt");
111
const unsigned int res = sceRtcGetTickResolution();
112
const unsigned int div = (SDL_NS_PER_SECOND / res);
113
sceTicks.tick = (Uint64)((ticks / div) + (DELTA_EPOCH_0001_OFFSET * div));
116
ret = sceRtcConvertUtcToLocalTime(&sceTicks, &sceLocalTicks);
118
sceLocalTicks.tick = sceTicks.tick;
122
ret = sceRtcSetTick(&t, &sceLocalTicks);
128
dt->minute = t.minute;
129
dt->second = t.second;
130
dt->nanosecond = ticks % SDL_NS_PER_SECOND;
131
dt->utc_offset = (int)(((Sint64)sceLocalTicks.tick - (Sint64)sceTicks.tick) / (Sint64)res);
133
SDL_CivilToDays(dt->year, dt->month, dt->day, &dt->day_of_week, NULL);
139
return SDL_SetError("Local time conversion failed (%i)", ret);