datetime_t TimePackToRel(const datepack_t *tp, bool_t Local) { static uint8_t Month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; datetime_t t; int a; if (tp->Year<1933 || tp->Year>=2069 || tp->Month<1 || tp->Month>12 || tp->Day<1 || tp->Day>31 || tp->Hour<0 || tp->Hour>=24 || tp->Minute<0 || tp->Minute>=60 || tp->Second<0 || tp->Second>=60) return INVALID_DATETIME_T; t = -2145916800; t += (tp->Day-1)*24*60*60; t += tp->Hour*60*60; t += tp->Minute*60; t += tp->Second; for (a=1933;a<tp->Year;++a) t += 24*60*60*(LeapYear(a) ? 366:365); for (a=1;a<tp->Month;++a) { t += Month[a-1]*24*60*60; if (a==2 && LeapYear(tp->Year)) t += 24*60*60; } if (Local) { int Timezone = configGetTimezone(); int DaylightSaving = configIsDaylightSavingEnabled(); t -= (Timezone + DaylightSaving * 60)*60; } return t; }
void OSystem_PS2::readRtcTime(void) { struct CdClock cdClock; readRTC(&cdClock); g_lastTimeCheck = getMillis(); if (cdClock.stat) { msgPrintf(5000, "Unable to read RTC time, EC: %d\n", cdClock.stat); g_day = g_month = 1; g_year = 0; g_timeSecs = 0; } else { int gmtOfs = configGetTimezone(); if (configIsDaylightSavingEnabled()) gmtOfs += 60; int timeSecs = (FROM_BCD(cdClock.hour) * 60 + FROM_BCD(cdClock.minute)) * 60 + FROM_BCD(cdClock.second); timeSecs -= 9 * 60 * 60; // minus 9 hours, JST -> GMT conversion timeSecs += gmtOfs * 60; // GMT -> timezone the user selected g_day = FROM_BCD(cdClock.day); g_month = FROM_BCD(cdClock.month); g_year = FROM_BCD(cdClock.year); if (timeSecs < 0) { buildNewDate(-1); timeSecs += SECONDS_PER_DAY; } else if (timeSecs >= SECONDS_PER_DAY) { buildNewDate(+1); timeSecs -= SECONDS_PER_DAY; } g_timeSecs = (uint32)timeSecs; } sioprintf("Time: %d:%02d:%02d - %d.%d.%4d\n", g_timeSecs / (60 * 60), (g_timeSecs / 60) % 60, g_timeSecs % 60, g_day, g_month, g_year + 2000); }
// converts the time returned from the ps2's clock into LOCAL time // (ps2 clock is in JST time) void configConvertToLocalTime(sceCdCLOCK* time) { int timezone_offset = configGetTimezone(); int daylight_saving = configIsDaylightSavingEnabled(); AdjustTime(time, timezone_offset - 540 + (daylight_saving * 60)); }
bool_t GetIsDst(datetime_t t) { //TODO: use t instead of current time return configIsDaylightSavingEnabled(); }
bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) { static const uint16_t Days[12] = { 0, 31, 31+28, 31+28+31, 31+28+31+30, 31+28+31+30+31, 31+28+31+30+31+30, 31+28+31+30+31+30+31, 31+28+31+30+31+30+31+31, 31+28+31+30+31+30+31+31+30, 31+28+31+30+31+30+31+31+30+31, 31+28+31+30+31+30+31+31+30+31+30, }; unsigned int a; unsigned int b; unsigned int c; if (!tp || t == INVALID_DATETIME_T) return 0; if (t<-2145916800) return 0; if (Local) { int Timezone = configGetTimezone(); int DaylightSaving = configIsDaylightSavingEnabled(); t += (Timezone + DaylightSaving * 60)*60; } a = t+2145916800; //2001 -> 1933 b = a % (24*60*60); a = a / (24*60*60); tp->Second = b %60; b /= 60; tp->Minute = b %60; tp->Hour = b /60; tp->WeekDay = 1 + a % 7; for (b=1933;;++b) { c = LeapYear(b) ? 366:365; if (a >= c) a -= c; else break; } tp->Year = b; tp->Day = 1; if (LeapYear(b) && a>58) { if (a==59) tp->Day = 2; --a; } for (b = 11; b && (Days[b] > a); --b) {} tp->Month = b+1; tp->Day += a - Days[b]; return 1; }