Skip to content

Commit dc1cc98

Browse files
authored
N-Gage: Add SDL_TimeToDateTime() implementation (#14141)
Add simple but working SDL_TimeToDateTime() implementation. Fixes #14047
1 parent bcf3afb commit dc1cc98

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/time/ngage/SDL_systime.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf)
152152

153153
bool SDL_GetCurrentTime(SDL_Time *ticks)
154154
{
155-
CHECK_PARAM(!ticks) {
155+
CHECK_PARAM(!ticks)
156+
{
156157
return SDL_InvalidParamError("ticks");
157158
}
158159

@@ -169,21 +170,39 @@ bool SDL_GetCurrentTime(SDL_Time *ticks)
169170
return true;
170171
}
171172

173+
#define SYMBIAN_UNIX_EPOCH_OFFSET_US 62135596800000000LL
174+
172175
bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime)
173176
{
174-
CHECK_PARAM(!dt) {
177+
CHECK_PARAM(!dt)
178+
{
175179
return SDL_InvalidParamError("dt");
176180
}
177181

178-
// FIXME: Need implementation
179-
dt->year = 1970;
180-
dt->month = 1;
181-
dt->day = 1;
182-
dt->hour = 0;
183-
dt->minute = 0;
184-
dt->second = 0;
185-
dt->nanosecond = 0;
186-
dt->day_of_week = 4;
182+
long long unixMicros = ticks / 1000LL;
183+
184+
unixMicros += SYMBIAN_UNIX_EPOCH_OFFSET_US;
185+
186+
TInt32 high = (TInt32)(unixMicros >> 32);
187+
TUint32 low = (TUint32)(unixMicros & 0xFFFFFFFFu);
188+
TInt64 symbianTime(high, low);
189+
190+
TTime s60Time(symbianTime);
191+
192+
if (localTime) {
193+
s60Time.HomeTime();
194+
}
195+
196+
TDateTime dtSym = s60Time.DateTime();
197+
198+
dt->year = dtSym.Year();
199+
dt->month = dtSym.Month() + 1; // Months are 0-11
200+
dt->day = dtSym.Day() + 1; // Days are 0-30
201+
dt->hour = dtSym.Hour();
202+
dt->minute = dtSym.Minute();
203+
dt->second = dtSym.Second();
204+
dt->nanosecond = (int)(ticks % 1000000000LL);
205+
dt->day_of_week = s60Time.DayNoInWeek();
187206
dt->utc_offset = 0;
188207

189208
return true;

0 commit comments

Comments
 (0)