Esempio n. 1
0
static void initialiseTimeFormat()
{
    if(timeFormat.Length())
        return;

    TLocale locale;
    //Separator 1 is used between 1st and 2nd components of the time
    //Separator 2 is used between 2nd and 3rd components of the time
    //Usually they are the same, but they are allowed to be different
    TChar s1 = locale.TimeSeparator(1);
    TChar s2 = locale.TimeSeparator(2);
    switch(locale.TimeFormat()) {
    case ETime12:
        timeFormat.Append(_L("%I"));
        break;
    case ETime24:
    default:
        timeFormat.Append(_L("%H"));
        break;
    }
    timeFormat.Append(s1);
    timeFormat.Append(_L("%T"));
    timeFormat.Append(s2);
    timeFormat.Append(_L("%S"));

#ifdef _DEBUG
    RDebug::Print(_L("Time Format \"%S\""), &timeFormat);
#endif
}
/*!

 */
void SettingsUtility::setDateFormat(const QString &format)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_SETDATEFORMAT_ENTRY );
	TLocale locale;
	int index;

	for (index = 0; index < mDisplayDateFormatList.count(); ++index) {
		if (format == mDisplayDateFormatList.at(index)) {
			break;
		}
	}

	switch (index) {
		case 0:
			locale.SetDateFormat(EDateEuropean);
			break;
		case 1:
			locale.SetDateFormat(EDateAmerican);
			break;
		case 2:
			locale.SetDateFormat(EDateJapanese);
			break;
		default:
			//Nothing to do.
			break;
	}

	locale.Set();
	OstTraceFunctionExit0( SETTINGSUTILITY_SETDATEFORMAT_EXIT );
}
/*!

 */
int SettingsUtility::dateSeparator(QStringList &separator)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_DATESEPARATOR_ENTRY );
	TLocale locale;
	TChar separatorChar = locale.DateSeparator(1);

	const int at0 = (mDateSeparatorList.at(0).unicode())->unicode();
	int at1 = (mDateSeparatorList.at(1).unicode())->unicode();
	int at2 = (mDateSeparatorList.at(2).unicode())->unicode();
	int at3 = (mDateSeparatorList.at(3).unicode())->unicode();
	int value = 0;

	if (separatorChar == (mDateSeparatorList.at(0).unicode())->unicode()) {
		value = 0;
	} else if (separatorChar ==
			(mDateSeparatorList.at(1).unicode())->unicode()) {
		value = 1;
	} else if (separatorChar ==
			(mDateSeparatorList.at(2).unicode())->unicode()) {
		value = 2;
	} else if (separatorChar ==
			(mDateSeparatorList.at(3).unicode())->unicode()) {
		value = 3;
	}

	separator = mDateSeparatorList;

	OstTraceFunctionExit0( SETTINGSUTILITY_DATESEPARATOR_EXIT );
	return value;
}
/*!

 */
int SettingsUtility::dateFormat(QStringList &format)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_DATEFORMAT_ENTRY );
	TLocale locale;
	int index = -1;

	switch (locale.DateFormat()) {
		case EDateEuropean:
			index = 0;
			break;
		case EDateAmerican:
			index = 1;
			break;
		case EDateJapanese:
			index = 2;
			break;
		default:
			// Nothing yet.
			break;
	}

	format = mDisplayDateFormatList;

	OstTraceFunctionExit0( SETTINGSUTILITY_DATEFORMAT_EXIT );
	return index;
}
/*!
    Retrieves Symbian locale group separator.
*/
static QString symbianGroupSeparator()
{
    TLocale *locale = _s60Locale.GetLocale();

    TChar grpSep = locale->ThousandsSeparator();
    int val = grpSep;
    return QChar(val);
}
/*!
    Retrieves Symbian locale decimal separator.
*/
static QString symbianDecimalPoint()
{
    TLocale *locale = _s60Locale.GetLocale();

    TChar decPoint = locale->DecimalSeparator();
    int val = decPoint;
    return QChar(val);
}
/*!
    Retrieves Symbian locale zero digit.
*/
static QString symbianZeroDigit()
{
    TLocale *locale = _s60Locale.GetLocale();

    // TDigitType enumeration value returned by TLocale
    // will always correspond to zero digit unicode value.
    TDigitType digit = locale->DigitType();
    return QChar(digit);
}
/*!
	Sets the start of week value selected by the user.

	\param index The index of the selected value.
 */
void SettingsUtility::setStartOfWeek(int index)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_SETSTARTOFWEEK_ENTRY );
	TLocale locale;
	TDay day = (TDay)index;
	locale.SetStartOfWeek(day);
	locale.Set();
	OstTraceFunctionExit0( SETTINGSUTILITY_SETSTARTOFWEEK_EXIT );
}
Esempio n. 9
0
/*
Intended Usage:	Utility routine for converting from UTC to localtime.
*/
inline time_t toLocal (const time_t aUniversalTime)
{
#ifndef __SERIES60_MRT_1_0
    TTimeIntervalSeconds offset = User::UTCOffset();
    return aUniversalTime + offset.Int();
#else
    TLocale locale;
    return aUniversalTime + locale.UniversalTimeOffset().Int();
#endif //__SERIES60_MRT_1_0
}
/*!

 */
void SettingsUtility::setDateSeparator(const QString &separator)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_SETDATESEPARATOR_ENTRY );
	TLocale locale;
	locale.SetDateSeparator(
			TChar(separator.unicode()->unicode()), 1);
	locale.SetDateSeparator(
			TChar(separator.unicode()->unicode()), 2);
	locale.Set();
	OstTraceFunctionExit0( SETTINGSUTILITY_SETDATESEPARATOR_EXIT );
}
Esempio n. 11
0
void TCalRRule::InitialiseData()
	{
	iBuffer = 0;
	iCount = 0;
	iUntil.SetTimeUtcL(Time::NullTTime()); // this can't leave
	iInterval = 1;
	TLocale locale;
	iWkSt = locale.StartOfWeek();
	iReserved = 0;
	iReserved2 = 0;
	}
// ---------------------------------------------------------------------------
// TPresCondValidity::ConvertToLocal()
// ---------------------------------------------------------------------------
//        
void TPresCondValidity::ConvertToLocal(TTime& aDateTime)
    {
    OPENG_DP(D_OPENG_LIT( " TPresCondValidity::ConvertToLocal()" ) );
    OPENG_DP(D_OPENG_LIT( "     ConvertToLocal aDateTime:"));
    LogDateTime(aDateTime.DateTime());

    TLocale myLocale;
    myLocale.Refresh();
    
    // getting UTC difference    
    TTimeIntervalSeconds uTCseconds = myLocale.UniversalTimeOffset();
    aDateTime = aDateTime + uTCseconds;
    }
/*!

 */
void SettingsUtility::setTimeSeparator(const QString &separator)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_SETTIMESEPARATOR_ENTRY );
	if (mTimeSeparatorList.contains(separator)) {
	    TLocale locale;

		locale.SetTimeSeparator(TChar(separator.unicode()->unicode()), 1);
		locale.SetTimeSeparator(TChar(separator.unicode()->unicode()), 2);

		locale.Set();
    }
	OstTraceFunctionExit0( SETTINGSUTILITY_SETTIMESEPARATOR_EXIT );
}
Esempio n. 14
0
RtoB_TEST::RtoB_TEST()
	{

	num=0.0;
	format.iType=KRealFormatGeneral;
	format.iWidth=KDefaultRealWidth;
	format.iPlaces=0;
	TLocale locale;
	format.iPoint=locale.DecimalSeparator();
	format.iTriad=locale.ThousandsSeparator();
	format.iTriLen=1;
	res=_S("0");
	}
/*!

 */
void SettingsUtility::setTimeFormat(const QString& format)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_SETTIMEFORMAT_ENTRY );
	TLocale locale;

	if (format == mTimeFormatList.at(0)) {
		locale.SetTimeFormat(ETime24);
	} else if (format == mTimeFormatList.at(1)) {
		locale.SetTimeFormat(ETime12);
	} else {
		// Nothing to do.
	}
	locale.Set();
	OstTraceFunctionExit0( SETTINGSUTILITY_SETTIMEFORMAT_EXIT );
}
Esempio n. 16
0
/**
Sets up the system-wide locale and language downgrade path for the new locale model.
*/
void REComLanguagePluginTest::SetLanguage(const TDesC& aLanguage,const TDesC& aReg,const TDesC& aColl,const TLanguage aLang[3])
    {
    TLocale locale;
    TExtendedLocale extendedLocale;
    TInt loadval = 0;

    extendedLocale.LoadSystemSettings();
    loadval = extendedLocale.LoadLocale(aLanguage,aReg,aColl);
    TEST(loadval==KErrNone, __LINE__);
    extendedLocale.SaveSystemSettings();

    locale.SetLanguageDowngrade(0, aLang[0]);
    locale.SetLanguageDowngrade(1, aLang[1]);
    locale.SetLanguageDowngrade(2, aLang[2]);
    locale.Set();
    }
/*!

 */
int SettingsUtility::timeFormat(QStringList &format)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_TIMEFORMAT_ENTRY );
	TLocale locale;
	int value = -1;

	if (ETime24 == locale.TimeFormat()) {
		value = 0;
	} else if (ETime12 == locale.TimeFormat()) {
		value = 1;
	}

	format = mTimeFormatList;

	OstTraceFunctionExit0( SETTINGSUTILITY_TIMEFORMAT_EXIT );
	return value;
}
/**
This routine is used to check if conversion of digits is needed.
Conversion is needed if user language is   
- Arabic, Urdu or Farsi and if digit type is Arabic-Indic
- Urdu or Farsi and digit type is Eastern Arabic_indic
- Hindi and digit type is Devanagari. 

@return  ETrue if conversion is needed, EFalse if not
*/
TBool CResourceLoader::LanguageSpecificNumberConverter::IsConversionNeeded()
    {
    TLocale locale;
    locale.Refresh();
    const TLanguage language = User::Language();
    const TDigitType digitType = locale.DigitType();
    
    if ( ( ( language == ELangArabic || language == ELangUrdu || language == ELangFarsi ) &&
         digitType == EDigitTypeArabicIndic ) 
         || ( ( language == ELangUrdu || language == ELangFarsi ) &&
         digitType == EDigitTypeEasternArabicIndic )
         || ( language == ELangHindi && digitType == EDigitTypeDevanagari )
        )
        {
        return ETrue;
        }

    return EFalse;
    }
/*!

 */
int SettingsUtility::timeSeparator(QStringList &list)
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_TIMESEPARATOR_ENTRY );
	TLocale locale;
	TChar separatorChar = locale.TimeSeparator(1);
	int value = -1;

	if (separatorChar == (mTimeSeparatorList.at(0).unicode())->unicode()) {
		value = 0;
	} else if (separatorChar == (mTimeSeparatorList.at(1).unicode())->unicode()) {
		value = 1;
	} else {
		// Nothing to do.
	}

	list = mTimeSeparatorList;
	OstTraceFunctionExit0( SETTINGSUTILITY_TIMESEPARATOR_EXIT );
	return value;
}
Esempio n. 20
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
}
/*!
	Returns a string based on the locale set, to format time.

	\return QString String to be used to format time.
 */
QString SettingsUtility::timeFormatString()
{
	OstTraceFunctionEntry0( SETTINGSUTILITY_TIMEFORMATSTRING_ENTRY );
	QString format;
	TLocale locale;
	QStringList dummyList;

	if (ETime24 == locale.TimeFormat()) {
		format = QString("hh:mm");
	} else if (ETime12 == locale.TimeFormat()) {
		format = QString("hh:mm ap");
	}

	QString separator = mTimeSeparatorList.at(timeSeparator(dummyList));

	format.replace(QString(":"), separator);

	OstTraceFunctionExit0( SETTINGSUTILITY_TIMEFORMATSTRING_EXIT );
	return format;
}
Esempio n. 22
0
void testChangeLocale(TInt isrom)
{
	TLocale locale;
	
#ifdef __WINS__
//We get a power-change notification 1 second after switch-on
//So we wait for a second on WINS.
//Should we fix this bug??
	User::After(1000000);
#endif
	RChangeNotifier notifier;
	TInt res=notifier.Create();
	test(res==KErrNone);
	TRequestStatus stat;
	res=notifier.Logon(stat);
	test(res==KErrNone);
	//initial pattern of stat is already tested by t_chnot

	res=notifier.Logon(stat);
	test(res==KErrNone);
	test(stat==KRequestPending);
	if (isrom == 0) 
		{
		test.Printf(_L("Change to RAM US Locale\n")); 	
		res=UserSvr::ChangeLocale(ELOCLUS);
		}
	else
		{
		test.Printf(_L("Change to ROM US Locale\n")); 	
		res=UserSvr::ChangeLocale(ELOCLUS_ROM);
		}
	test.Printf(_L("res=%d\n"),res);
	test(res==KErrNone);
	test(stat.Int() & EChangesLocale);
	res=notifier.Logon(stat);
	test(res==KErrNone);
	test(stat==KRequestPending);
	
	locale.Refresh();
	testUS(locale);
}
Esempio n. 23
0
static void initialiseDateFormat()
{
    if(dateFormat.Length())
        return;

    TLocale locale;

    //Separator 1 is used between 1st and 2nd components of the date
    //Separator 2 is used between 2nd and 3rd components of the date
    //Usually they are the same, but they are allowed to be different
    TChar s1 = locale.DateSeparator(1);
    TChar s2 = locale.DateSeparator(2);
    dateFormat=KLocaleIndependent;
    switch(locale.DateFormat()) {
    case EDateAmerican:
        dateFormat.Append(KMonth);
        dateFormat.Append(s1);
        dateFormat.Append(KDay);
        dateFormat.Append(s2);
        dateFormat.Append(KYear);
        break;
    case EDateEuropean:
        dateFormat.Append(KDay);
        dateFormat.Append(s1);
        dateFormat.Append(KMonth);
        dateFormat.Append(s2);
        dateFormat.Append(KYear);
        break;
    case EDateJapanese:
    default: //it's closest to ISO format
        dateFormat.Append(KYear);
        dateFormat.Append(s1);
        dateFormat.Append(KMonth);
        dateFormat.Append(s2);
        dateFormat.Append(KDay);
        break;
    }
#ifdef _DEBUG
    RDebug::Print(_L("Date Format \"%S\""), &dateFormat);
#endif
}
Esempio n. 24
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;
}
/**
This routine is used to convert between European digits and 
Arabic-Indic, Eastern Arabic-Indic, Devanagari or Thai digits 
based on existing digit type setting. 

@param aDes  Parameter to change
*/
void CResourceLoader::LanguageSpecificNumberConverter::Convert( TDes &aDes )
    {   
    TLocale locale;
    locale.Refresh();
    const TDigitType digitType = locale.DigitType();
    TChar toArea = 0x030;
    switch( digitType )
        {
        case EDigitTypeWestern:
        case EDigitTypeArabicIndic:
        case EDigitTypeEasternArabicIndic:
        case EDigitTypeDevanagari:
        case EDigitTypeThai:
            toArea = digitType;
            break;
        case EDigitTypeUnknown:
        case EDigitTypeAllTypes:
            return;
        }
    
    const TInt length = aDes.Length();
    for( TInt i = 0; i < length; i++ )
        {
        TChar character = aDes[i];
        TChar fromArea = NumberToBase( character );
        TChar::TBdCategory cat = character.GetBdCategory();
        switch( cat )
            {
            case TChar::EArabicNumber:
            case TChar::EEuropeanNumber:
                character += toArea;
                character -= fromArea;
                aDes[i] = TUint16( character );
                break;
            default: 
                break;
            }
        }
    }
Esempio n. 26
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);
}
/**
* Current implementation of this should work for any RTL language if it sets the 
* digit type to digit types checked for below
*
* It is meant as a patch for S60 2.0, not as a complete solution to the problem of date
* presentation.
*/
TBool AknDateFormatUtils::DateFieldReOrderingNeeded(TLanguage* aForceLanguage )
    {
    TBool reorderingNeeded(EFalse);
    TLocale locale;
    TLanguage language = (aForceLanguage != NULL) ? *aForceLanguage : AknLangUtils::UserLanguage();

    // Reordering needed in case of RTL language, we have arabic digits and if the separator is not 
    // numeric separator.
     if ( TBidiText::ScriptDirectionality( language ) == TBidiText::ERightToLeft )
        {
        TInt digitType = locale.DigitType();
        if ( digitType == EDigitTypeArabicIndic ||
             digitType == EDigitTypeEasternArabicIndic )
            {
            TChar sep( locale.DateSeparator(1) );
            if ( sep.GetBdCategory() != TChar::ECommonNumberSeparator )
                {
                reorderingNeeded = ETrue;
                }
            }
        }
        
    return reorderingNeeded;
    }
Esempio n. 28
0
TBool Util::DaylightSavingsAppliesL(const TTime& utc)
	{
	
	// This algorithm needs the first day of the week to be monday
	
	TDay oldStart;
	
	TLocale set;
	oldStart = set.StartOfWeek();
	set.SetStartOfWeek(EMonday);
	set.Set();
	
	TBuf<9> min;
	TBuf<9> max;
	
	utc.FormatL(min, KDaylightSavingsMinFormat);
	utc.FormatL(max, KDaylightSavingsMaxFormat);
	
	// Get times representing the first/last possible day of this 
	// year that daylight savings time change could change on
	
	TTime timeMin;
	User::LeaveIfError(timeMin.Set(min));
	TTime timeMax;
	User::LeaveIfError(timeMax.Set(max));

	// Find the last sunday in the respective months
	
	TTimeIntervalDays addMin(6 - timeMin.DayNoInWeek());
	TTimeIntervalDays addMax(6 - timeMax.DayNoInWeek());
	
	timeMin += addMin;
	timeMax += addMax;
	
	// The change happens at 1AM.
	TTimeIntervalHours hour(1);
	timeMin += hour;
	timeMax += hour;
	
	// Now we know which day the change occurs on.
	// Compare it to what the UTC is.

	TBool result = ((timeMin <= utc) && (timeMax > utc));
	
	// reset the first week day
	set.SetStartOfWeek(oldStart);
	set.Set();
	
	return result;
	
	}
Esempio n. 29
0
/*!
    Returns a Qt version of the given \a sys_fmt Symbian locale format string.
*/
static QString s60ToQtFormat(const QString &sys_fmt)
{
    TLocale *locale = _s60Locale.GetLocale();

    QString result;
    QString other;
    QString qtformatchars = QString::fromLatin1("adhmsyzAHM");

    QChar c;
    int i = 0;
    bool open_escape = false;
    bool abbrev_next = false;
    bool locale_indep_ordering = false;
    bool minus_mode = false;
    bool plus_mode = false;
    bool n_mode = false;
    TTimeFormat tf = locale->TimeFormat();

    while (i < sys_fmt.size()) {

        c = sys_fmt.at(i);

        // let formatting thru
        if (c.unicode() == '%') {
            // if we have gathered string, concat it
            if (!other.isEmpty()) {
                result += other;
                other.clear();
            }
            // if we have open escape, end it
            if (open_escape) {
                result += QLatin1Char('\'');
                open_escape = false;
            }

            ++i;
            if (i >= sys_fmt.size())
                break;

            c = sys_fmt.at(i);

            // process specials
            abbrev_next = c.unicode() == '*';
            plus_mode = c.unicode() == '+';
            minus_mode = c.unicode() == '-';

            if (abbrev_next || plus_mode || minus_mode) {
                ++i;
                if (i >= sys_fmt.size())
                    break;

                c = sys_fmt.at(i);

                if (plus_mode || minus_mode) {
                    // break on undefined plus/minus mode
                    if (c.unicode() != 'A' && c.unicode() != 'B')
                        break;
                }
            }

            switch (c.unicode()) {
                case 'F':
                {
                    // locale indep mode on
                    locale_indep_ordering = true;
                    break;
                }

                case '/':
                {
                    // date sep 0-3
                    ++i;
                    if (i >= sys_fmt.size())
                        break;

                    c = sys_fmt.at(i);
                    if (c.isDigit() && c.digitValue() <= 3) {
                        TChar s = locale->DateSeparator(c.digitValue());
                        TUint val = s;
                        // some indexes return zero for empty
                        if (val > 0)
                            result += QChar(val);
                    }
                    break;
                }

                case 'D':
                {
                    if (!locale_indep_ordering)
                        break;

                    if (!abbrev_next)
                        result += QLatin1String("dd");
                    else
                        result += QLatin1Char('d');

                    break;
                }

                case 'M':
                {
                    if (!locale_indep_ordering)
                        break;

                    if (!n_mode) {
                        if (!abbrev_next)
                            result += QLatin1String("MM");
                        else
                            result += QLatin1String("M");
                    } else {
                        if (!abbrev_next)
                            result += QLatin1String("MMMM");
                        else
                            result += QLatin1String("MMM");
                    }

                    break;
                }

                case 'N':
                {
                    n_mode = true;

                    if (!locale_indep_ordering)
                        break;

                    if (!abbrev_next)
                        result += QLatin1String("MMMM");
                    else
                        result += QLatin1String("MMM");

                    break;
                }

                case 'Y':
                {
                    if (!locale_indep_ordering)
                        break;

                    if (!abbrev_next)
                        result += QLatin1String("yyyy");
                    else
                        result += QLatin1String("yy");

                    break;
                }

                case 'E':
                {
                    if (!abbrev_next)
                        result += QLatin1String("dddd");
                    else
                        result += QLatin1String("ddd");

                    break;
                }

                case ':':
                {
                    // timesep 0-3
                    ++i;
                    if (i >= sys_fmt.size())
                        break;

                    c = sys_fmt.at(i);
                    if (c.isDigit() && c.digitValue() <= 3) {
                        TChar s = locale->TimeSeparator(c.digitValue());
                        TUint val = s;
                        // some indexes return zero for empty
                        if (val > 0)
                            result += QChar(val);
                    }

                    break;
                }

                case 'J':
                {
                    if (tf == ETime24 && !abbrev_next)
                        result += QLatin1String("hh");
                    else
                        result += QLatin1Char('h');

                    break;
                }

                case 'H':
                {
                    if (!abbrev_next)
                        result += QLatin1String("hh");
                    else
                        result += QLatin1Char('h');

                    break;
                }

                case 'I':
                {
                    result += QLatin1Char('h');
                    break;
                }

                case 'T':
                {
                    if (!abbrev_next)
                        result += QLatin1String("mm");
                    else
                        result += QLatin1Char('m');

                    break;
                }

                case 'S':
                {
                    if (!abbrev_next)
                        result += QLatin1String("ss");
                    else
                        result += QLatin1Char('s');

                    break;
                }

                case 'B':
                {
                    // only done for 12h clock
                    if (tf == ETime24)
                        break;
                }

                    // fallthru to A
                case 'A': {
                    // quickie to get capitalization, can't use s60 string as is because Qt 'hh' format's am/pm logic
                    TAmPmName ampm = TAmPmName();
                    TChar first(ampm[0]);
                    QString qtampm = QString::fromLatin1(first.IsUpper() ? "AP" : "ap");

                    int pos = locale->AmPmSymbolPosition();

                    if ((minus_mode && pos != ELocaleBefore) ||
                        (plus_mode && pos != ELocaleAfter))
                        break;

                    if (!abbrev_next && locale->AmPmSpaceBetween()) {
                        if (pos == ELocaleBefore)
                            qtampm.append(QLatin1Char(' '));
                        else
                            qtampm.prepend(QLatin1Char(' '));
                    }

                    result += qtampm;
                    }
                    break;

                case '.': {
                        // decimal sep
                        TChar s = locale->DecimalSeparator();
                        TUint val = s;
                        if (val > 0)
                            result += QChar(val);
                    }
                    break;

                case 'C':
                {
                    // six digits in s60, three digits in qt
                    if (!abbrev_next) {
                        result += QLatin1String("zzz");
                    } else {
                        // next char is number from 0-6, how many digits to display
                        ++i;
                        if (i >= sys_fmt.size())
                            break;

                        c = sys_fmt.at(i);

                        if (c.isDigit()) {
                            // try to match wanted digits
                            QChar val(c.digitValue());

                            if (val >= 3) {
                                result += QLatin1String("zzz");
                            } else if (val > 0) {
                                result += QLatin1Char('z');
                            }
                        }
                    }
                    break;
                }

                // these cases fallthru
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                {

                    // shouldn't parse these with %F
                    if (locale_indep_ordering)
                        break;

                    TDateFormat df = locale->DateFormat();

                    const char **locale_dep;
                    switch (df) {
                        default: // fallthru to american
                        case EDateAmerican:
                            locale_dep = us_locale_dep;
                            break;
                        case EDateEuropean:
                            locale_dep = eu_locale_dep;
                            break;
                        case EDateJapanese:
                            locale_dep = jp_locale_dep;
                            break;
                    }
                    int offset = 0;
                    if (abbrev_next)
                        offset += 5;
                    if (n_mode)
                        offset += 10;

                    result += QLatin1String(locale_dep[offset + (c.digitValue()-1)]);
                    break;
                }

                case '%': // fallthru percent
                {
                // any junk gets copied as is
                }
                default:
                {
                    result += c;
                    break;
                }

                case 'Z': // Qt doesn't support these :(
                case 'X':
                case 'W':
                {
                    break;
                }
            }
        } else {
            // double any single quotes, don't begin escape
            if (c.unicode() == '\'') {
                // end open escape
                if (open_escape) {
                    result += other;
                    other.clear();
                    result += QLatin1Char('\'');
                    open_escape = false;
                }

                other += c;
            }

            // gather chars and escape them in one go if any format chars are found
            if (!open_escape && qtformatchars.indexOf(c) != -1) {
                result += QLatin1Char('\'');
                open_escape = true;
            }
            other += c;
        }

        ++i;
    }

    if (!other.isEmpty())
        result += other;
    if (open_escape)
        result += QLatin1Char('\'');

    return result;
}
Esempio n. 30
0
/**
@SYMTestCaseID          SYSLIB-LOGENG-CT-0883
@SYMTestCaseDesc	    Tests for CLogClient::ClearLog() function
@SYMTestPriority 	    High
@SYMTestActions  	    Change locale settings,call up ClearLog and try to retrieve event,test for count of number of events in the view.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestClearLog2L(CLogClient& aClient)
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0883 "));
	CLogEvent* event = CLogEvent::NewL();
	CleanupStack::PushL(event);
	event->SetEventType(KLogCallEventTypeUid);

	CTestActive* active = new(ELeave)CTestActive();
	CleanupStack::PushL(active);

	CLogViewEvent* view = CLogViewEvent::NewL(aClient);
	CleanupStack::PushL(view);

	// change Locale
	TLocale locale;
	locale.SetCountryCode(47);//Norway
	locale.SetDateFormat(EDateEuropean);
	locale.SetTimeFormat(ETime12);
	for (int i=0; i<4; i++)
         {
         locale.SetTimeSeparator(TChar('.'),i);
         locale.SetDateSeparator(TChar(':'),i);
         }
	locale.Set();

	// change the log duration settings to 1 day  
	TLogConfig config;
	active->StartL();
	aClient.GetConfig(config, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);

	config.iMaxLogSize = KTestEventAge * 2;
	config.iMaxEventAge = 86400;
	active->StartL();
	aClient.ChangeConfig(config, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);

	// add a call event
	active->StartL();
	aClient.AddEvent(*event, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);
	User::After(1000000);
	TTime now;
	now.HomeTime();	
	event->SetTime(now);
	active->StartL();
	aClient.ChangeEvent(*event, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);

	// forward two days
	now+=(TTimeIntervalDays )2;
	User::SetHomeTime(now);
		
	active->StartL();
	aClient.ClearLog(now, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);

	// try to retrieve event
	active->StartL();
	aClient.GetEvent(*event, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNotFound);;

	TEST(view->CountL() == 0);

	CleanupStack::PopAndDestroy(3); // view, active, event
	}