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;
}
示例#2
0
文件: ps2time.cpp 项目: 33d/scummvm
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);
}
示例#3
0
// 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));
}
示例#4
0
int ps2time_init( void )
{
	CdvdClock_t clock;
	struct tm	tm_time;

	static unsigned int monthdays[12] = {
		31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
	};

	// query the RTC
	cdInit(CDVD_INIT_NOCHECK);
	if( !cdReadClock(&clock) )
		return -1;

	tm_time.tm_sec	= BCD2DEC(clock.second);
	tm_time.tm_min	= BCD2DEC(clock.minute);
	tm_time.tm_hour = BCD2DEC(clock.hour); // hour in Japan (GMT + 9)
	tm_time.tm_mday	= BCD2DEC(clock.day);
	tm_time.tm_mon	= BCD2DEC(clock.month) - 1; // RTC months range from 1 - 12
	tm_time.tm_year	= BCD2DEC(clock.year) + 100; // RTC returns year less 2000

	if( tm_time.tm_hour < 9 ) {
		// go back to last month
		if( tm_time.tm_mday == 1 ) {

			// go back to last year if month is january
			if( tm_time.tm_mon == 0 ) {
				tm_time.tm_mon = 11;
				tm_time.tm_year = tm_time.tm_year - 1;
			}
			else {
				tm_time.tm_mon = tm_time.tm_mon - 1;
			}

			// if going back to february and year is a leapyear
			if( tm_time.tm_mon == 1 && IS_LEAP_YEAR(tm_time.tm_year + 1900)) {
				tm_time.tm_mday = 29;
			}
			else {
				tm_time.tm_mday = monthdays[ tm_time.tm_mon ];
			}

		}
		else {
			tm_time.tm_mday = tm_time.tm_mday - 1;
		}
		tm_time.tm_hour = (24 - (9 - tm_time.tm_hour)) % 24;
	}
	else {
		tm_time.tm_hour -= 9;
	}

	g_ps2time_start = ps2time_mktime(&tm_time);

	// setup EE timer1
	*T1_MODE = 0x0000;

	// enable the overflow interrupt handler
	g_interruptID = AddIntcHandler(T1_INTC, ps2time_intr_handler, 0);
	EnableIntc(T1_INTC);
	g_interruptCount = 0;

	*T1_COUNT	= 0;
	*T1_MODE	= Tn_MODE(0x02, 0, 0, 0, 0, 0x01, 0, 0x01, 0, 0);

	// set the timezone as offset in minutes from GMT
	ps2time_setTimezone( configGetTimezone() );

	return 0;
}
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;
}