Пример #1
0
bool_t GetIsDst(datetime_t UNUSED_PARAM(t))
{
#ifndef SYMBIAN90
    TLocale locale;
    return locale.QueryHomeHasDaylightSavingOn();
#else
    TBool IsDst=EFalse;
    RTz TzServer;
    if (TzServer.Connect()==KErrNone)
    {
        CTzConverter* Converter = CTzConverter::NewL(TzServer); 
        CTzId* TzId = CTzId::NewL(Converter->CurrentTzId());
        IsDst = TzServer.IsDaylightSavingOnL(*TzId);
        delete TzId;
        delete Converter;
        TzServer.Close();
    }
    return IsDst;
#endif
}
Пример #2
0
bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local)
{
	TDateTime Date;
    TTime ot;
	if (!tp || t == INVALID_DATETIME_T) return 0;
	
    ot = DateTimeToSymbian(t);

    if (Local) 
    {
#ifndef SYMBIAN90
        TLocale locale;
        TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset());
        ot += universalTimeOffset;
        if (locale.QueryHomeHasDaylightSavingOn())
        {
            TTimeIntervalHours daylightSaving(1);
            ot += daylightSaving;
        }
#else
        RTz TzServer;
        if (TzServer.Connect()==KErrNone)
        {
            CTzConverter* Converter = CTzConverter::NewL(TzServer); 
            Converter->ConvertToLocalTime(ot);
            delete Converter;
            TzServer.Close();
        }
#endif
    }

	Date = ot.DateTime();
	tp->Year = Date.Year();
	tp->Month = (int)Date.Month() + 1;
	tp->Day = Date.Day()+1;
	tp->Hour = Date.Hour();
	tp->Minute = Date.Minute();
	tp->Second = Date.Second();
	return 1;
}
Пример #3
0
datetime_t TimePackToRel(const datepack_t *tp, bool_t Local)
{
    TDateTime Date;
    TTime ot;
	if (!tp) return INVALID_DATETIME_T;
    Date.SetYear(tp->Year);
    Date.SetMonth((TMonth)(tp->Month-1));
    Date.SetDay(tp->Day-1);
    Date.SetHour(tp->Hour);
    Date.SetMinute(tp->Minute);
    Date.SetSecond(tp->Second);

    ot = TTime(Date);

    if (Local) 
    {
#ifndef SYMBIAN90
        TLocale locale;
        TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset());
        ot -= universalTimeOffset;
        if (locale.QueryHomeHasDaylightSavingOn())
        {
            TTimeIntervalHours daylightSaving(1);
            ot -= daylightSaving;
        }
#else
        RTz TzServer;
        if (TzServer.Connect()==KErrNone)
        {
            CTzConverter* Converter = CTzConverter::NewL(TzServer); 
            Converter->ConvertToUniversalTime(ot);
            delete Converter;
            TzServer.Close();
        }
#endif
    }

    return SymbianToDateTime(ot);
}
Пример #4
0
/** Convert times using multiple TZ converter objects
*/	
void CTestTZServer::MulitpleTZConverterL()
	{
	CActiveScheduler* scheduler;
	scheduler = new CActiveScheduler();
	CleanupStack::PushL(scheduler);  
	CActiveScheduler::Install(scheduler);
	
	TPtrC	ptrSystemTime;
	TESTL(GetStringFromConfig(ConfigSection(), KTime, ptrSystemTime));
	TTime	time(ptrSystemTime);	
	
	_LIT8(KEuropeLondon, "Europe/London");
	CTzId* zoneId = CTzId::NewL(KEuropeLondon);
	
	CleanupStack::PushL(zoneId);

	RTz tz;
	CTzConverter* timeConverter = NULL;
	CTzConverter* timeConverter1 = NULL;
	CTzConverter* timeConverter2 = NULL;
	CTzConverter* timeConverter3 = NULL;
	CTzConverter* timeConverter4 = NULL;
	CTzConverter* timeConverter5 = NULL;
	CTzConverter* timeConverter6 = NULL;
	CTzConverter* timeConverter7 = NULL;

	CleanupClosePushL(tz);
	User::LeaveIfError(tz.Connect());
	
	TRAPD(err,timeConverter = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter);

	TRAP(err,timeConverter1 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter1);
	
	TRAP(err,timeConverter2 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter2);
	
	TRAP(err,timeConverter3 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter3);
	
	TRAP(err,timeConverter4 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter4);
	
	TRAP(err,timeConverter5 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter5);
	
	TRAP(err,timeConverter6 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter6);
	
	TRAP(err,timeConverter7 = CTzConverter::NewL(tz));
	TESTL(err == KErrNone);
	CleanupStack::PushL(timeConverter7);
	
	TRAP(err, timeConverter->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter1->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter2->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter3->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter4->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter5->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter6->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter7->ConvertToLocalTime(time, *zoneId));
	TESTL(err == KErrNone);
	
	TRAP(err, timeConverter->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter1->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter2->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter3->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter4->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter5->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter6->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter7->ConvertToLocalTime(time));
	TESTL(err == KErrNone);
	
	TRAP(err, timeConverter->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter1->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter2->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter3->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter4->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter5->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter6->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter7->ConvertToUniversalTime(time));
	TESTL(err == KErrNone);
	
	TRAP(err, timeConverter->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter1->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter2->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter3->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter4->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter5->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter6->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	TRAP(err, timeConverter7->ConvertToUniversalTime(time, *zoneId));
	TESTL(err == KErrNone);
	
	CleanupStack::PopAndDestroy(timeConverter7);
	CleanupStack::PopAndDestroy(timeConverter6);
	CleanupStack::PopAndDestroy(timeConverter5);
	CleanupStack::PopAndDestroy(timeConverter4);
	CleanupStack::PopAndDestroy(timeConverter3);
	CleanupStack::PopAndDestroy(timeConverter2);
	CleanupStack::PopAndDestroy(timeConverter1);
	CleanupStack::PopAndDestroy(timeConverter);
	CleanupStack::PopAndDestroy(&tz);
	CleanupStack::PopAndDestroy(zoneId);
	
	CleanupStack::PopAndDestroy(scheduler);
	
	CActiveScheduler::Install(NULL);
	}
Пример #5
0
/** Performs time conversions (in OOM conditions) to local/universal times either using system or specified time zone
*/
void CTestTZServer::OOMTimeConversionsL()
	{
	CActiveScheduler* scheduler;
	scheduler = new CActiveScheduler();
	CleanupStack::PushL(scheduler);  
	CActiveScheduler::Install(scheduler);
		
	_LIT8(KEuropeLondon, "Europe/London");
	CTzId* zoneId = CTzId::NewL(KEuropeLondon);
	
	CleanupStack::PushL(zoneId);

	RTz tz;
	CTzConverter* timeConverter = NULL;
	CleanupClosePushL(tz);
	User::LeaveIfError(tz.Connect());
	
	TRAPD(err, timeConverter = CTzConverter::NewL(tz));
	TESTL( err == KErrNone );
	
	CleanupStack::PushL(timeConverter);	
	
	TPtrC	ptrSystemTime;
	TESTL(GetStringFromConfig(ConfigSection(), KTime, ptrSystemTime));
	TTime	time(ptrSystemTime);
	
	iFailAt = 1;
	for ( ;; )
		{
		StartHeapCheck(iFailAt);
		TInt err = timeConverter->ConvertToLocalTime(time);
		 
		if ( err == KErrNone )
			{
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of ConvertToLocalTime Api (using current time zone) is done"));
			break;
			}
				
		if ( ErrorProcess(err) )
			{
			EndHeapCheck();
			}
		else
			{
			break;
			}
		}
		
	iFailAt = 1;
	for ( ;; )
		{
		StartHeapCheck(iFailAt);
		TInt err = timeConverter->ConvertToLocalTime(time, *zoneId);
		 
		if ( err == KErrNone )
			{
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of ConvertToLocalTime Api (specifiying time zone) is done"));
			break;
			}
				
		if ( ErrorProcess(err) )
			{
			EndHeapCheck();
			}
		else
			{
			break;
			}
		}	
		
	iFailAt = 1;
	for ( ;; )
		{
		StartHeapCheck(iFailAt);
		TInt err = timeConverter->ConvertToUniversalTime(time);
		 
		if ( err == KErrNone )
			{
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of ConvertToUniversalTime Api (using current time zone) is done"));
			break;
			}
				
		if ( ErrorProcess(err) )
			{
			EndHeapCheck();
			}
		else
			{
			break;
			}
		}	
		
	iFailAt = 1;
	for ( ;; )
		{
		StartHeapCheck(iFailAt);
		TInt err = timeConverter->ConvertToUniversalTime(time, *zoneId);
		 
		if ( err == KErrNone )
			{
			__UHEAP_RESET;
			INFO_PRINTF1(_L("OOM testing of ConvertToUniversalTime (specifiying time zone) Api is done"));
			break;
			}
				
		if ( ErrorProcess(err) )
			{
			EndHeapCheck();
			}
		else
			{
			break;
			}
		}	
		
	CleanupStack::PopAndDestroy(timeConverter);
	CleanupStack::PopAndDestroy(&tz);
	CleanupStack::PopAndDestroy(zoneId);
	CleanupStack::PopAndDestroy(scheduler);
	
	CActiveScheduler::Install(NULL);
	}
Пример #6
0
TInt CConvertTime::CreateAndRunTestUnitL()
{
    TTime t;
    TInt converterErrUTC = KErrNone;
    TInt rulesErrUTC = KErrNone;
    TInt converterErrLocal = KErrNone;
    TInt rulesErrLocal = KErrNone;

    User::LeaveIfError(iTimeZoneServer.Connect());

    // Set home location
    TInt err = CDstIntUtils::SetHomeTimeZoneL(iCityName, iTimeZoneServer);

    if (iSystemLocalTime != Time::NullTTime())
    {
        iTimeZoneServer.SetHomeTime(iSystemLocalTime);
    }

    // Instantiate Converter
    CTzConverter *converter = CTzConverter::NewL(iTimeZoneServer);
    CleanupStack::PushL(converter);

    CTzId* tzId = CTzId::NewL(iCityName);
    CleanupStack::PushL(tzId);
    CTzRules* rules = iTimeZoneServer.GetTimeZoneRulesL(*tzId, TDateTime(0, EJanuary, 0, 0, 0, 0, 0), TDateTime(9999, EJanuary, 0, 0, 0, 0, 0), ETzWallTimeReference);
    CleanupStack::PopAndDestroy(tzId);
    CleanupStack::PushL(rules);

    if(err != KErrNone)
    {
        TBuf8<64> txt;
        txt.Append(_L8("Zone not set: "));
        txt.Append(iCityName);
        TBuf<64> txtmsg;
        txtmsg.Copy(txt);
        LogCheck(txtmsg, err);
    }
    else
    {
        // Handle UTC to local conversion
        if((iConversion == EConvertUTC) || (iConversion == EConvertBoth))
        {
            t = iUTCTime;
            converterErrUTC = converter->ConvertToLocalTime(t);
            if(converterErrUTC == KErrNone)
            {
                converterErrUTC = CompareTimesL(t, EConvertUTC);
            }

            t = iUTCTime;
            TRAP(rulesErrUTC, rules->ConvertToLocalL(t));
            if(rulesErrUTC == KErrNone)
            {
                rulesErrUTC = CompareTimesL(t, EConvertUTC);
            }
        }

        // Handle local to UTC conversion
        if((iConversion == EConvertLocal) || (iConversion == EConvertBoth))
        {
            t = iLocalTime;
            converterErrLocal = converter->ConvertToUniversalTime(t);
            if(converterErrLocal == KErrNone)
            {
                converterErrLocal = CompareTimesL(t, EConvertLocal);
            }

            t = iLocalTime;
            TRAP(rulesErrLocal, rules->ConvertToUtcL(t));
            if(rulesErrLocal == KErrNone)
            {
                rulesErrLocal = CompareTimesL(t, EConvertLocal);
            }
        }

        if(converterErrUTC != KErrNone)
            err = converterErrUTC;
        if(converterErrLocal != KErrNone)
            err = converterErrLocal;
        if(rulesErrUTC != KErrNone)
            err = rulesErrUTC;
        if(rulesErrLocal != KErrNone)
            err = rulesErrLocal;
    }

    CleanupStack::PopAndDestroy(rules);
    CleanupStack::PopAndDestroy(converter);

    return err;
}
/**
* Tests the new design from 9.3 where caching is done in RTz. This function
* does little verification other than exercising the API.
*/
TInt CTzCachingTestStep::CreateAndRunTestUnitL()
    {
    // Connect and do some conversions using non-cached method.
    User::LeaveIfError( iTzServer.Connect() );

    TTime cachedLocalTime;
    User::LeaveIfError( iTzServer.ConvertToLocalTime( cachedLocalTime ) );
    
    TTime cachedUniTime;
    User::LeaveIfError( iTzServer.ConvertToUniversalTime( cachedUniTime ) );
    
    // Get the time zone.
    CTzId* tzIdCached = iTzServer.GetTimeZoneIdL();
    CleanupStack::PushL( tzIdCached );
    TUint tzId1 = tzIdCached->TimeZoneNumericID();

    // Close connection to server and re-connect.
    iTzServer.Close();
    User::LeaveIfError( iTzServer.Connect() );
    
    TTime cachedLocalTime2;
    User::LeaveIfError( iTzServer.ConvertToLocalTime( cachedLocalTime2 ) );

    // Close connection to server. 
    iTzServer.Close();

    // Re-connect.
    User::LeaveIfError( iTzServer.Connect() );
    
    // Now do another conversion.
    TTime cachedUniTime2;
    User::LeaveIfError( iTzServer.ConvertToUniversalTime( cachedUniTime2 ) );

    // Set time zone.
    iTzServer.SetTimeZoneL( *tzIdCached );
    CleanupStack::PopAndDestroy( tzIdCached );

    // Get the time zone again.
    CTzId* tzIdCached2 = iTzServer.GetTimeZoneIdL();
    TUint tzId2 = tzIdCached2->TimeZoneNumericID();
    delete tzIdCached2;
    
    if (tzId1 != tzId2)
        {
        return KErrGeneral;
        }
    
    iTzServer.Close();

    // ---- Test converter ----

    // Create converter with unconnected RTz. This should leave.
    TRAPD( err, CTzConverter* conv = CTzConverter::NewL( iTzServer ));
    if (err != KErrNotReady)
        {
        return KErrGeneral;
        }

    // Create converter with connected RTz. Should be fine.
    User::LeaveIfError( iTzServer.Connect() );
    CTzConverter* conv = NULL;
    TRAP( err, conv = CTzConverter::NewL( iTzServer ));
    if (err != KErrNone)
        {
        return KErrGeneral;
        }
    CleanupStack::PushL( conv );
    TUint16 tz = conv->CurrentTzId();
    
    // Close session and re-open. Caching rules should be cleared and
    // then caching should be enabled again once re-connected.
    iTzServer.Close();
    User::LeaveIfError( iTzServer.Connect() );
    
    // Get the time again using cached method.
    TTime cachedLocalTime3;
    cachedLocalTime3.UniversalTime();
    User::LeaveIfError( conv->ConvertToLocalTime( cachedLocalTime3 ) );

    TTime cachedUniTime3;
    cachedUniTime3.HomeTime();
    User::LeaveIfError( conv->ConvertToUniversalTime( cachedUniTime3 ) );

    // The timezone should be the same as before.    
    TUint16 tzidConv = conv->CurrentTzId();
    if (tzidConv != tzId2)
        {
        return KErrGeneral;
        }
        
    // Close the session and try doing a conversion, it should leave with
    // KErrNotReady because the session is closed. Even though caching is
    // done without making requests to the server, a connection is still 
    // required for tz change notifications so that the client can ensure the 
    // cache is valid.
    iTzServer.Close();
    TTime cachedUniTime4;
    err = conv->ConvertToUniversalTime( cachedUniTime4 );
    if (err != KErrNotReady)
        {
        return KErrGeneral;
        }
    
    // Reconnect to the server and do a conversion. Caching is currently
    // disabled but should be enabled when the conversion call is made, it 
    // should be successful.
    User::LeaveIfError( iTzServer.Connect() );
    TTime cachedUniTime5;
    cachedUniTime5.HomeTime();
    err = conv->ConvertToUniversalTime( cachedUniTime5 );
    if (err != KErrNone)
        {
        return KErrGeneral;
        }

    CleanupStack::PopAndDestroy( conv );
    
    return KErrNone;
    }