Commit 3eb6a91e authored by Joao Oliveira's avatar Joao Oliveira

Changed util.printd to use the default locale on case 2. Also made...

Changed util.printd to use the default locale on case 2. Also made kjsfunctionstest to be in a consistent locale
parent 1c1a073c
Pipeline #6667 passed with stage
in 14 minutes and 10 seconds
......@@ -333,6 +333,10 @@ private:
void KJSFunctionsTest::testPrintD_data()
{
// Force consistent locale
QLocale locale( QStringLiteral( "en_US" ) );
QLocale::setDefault( locale );
QTest::addColumn<QString>("script");
QTest::addColumn<QString>("result");
......@@ -359,11 +363,10 @@ void KJSFunctionsTest::testPrintD_data()
<< QStringLiteral( "ret = app.alert( util.printd( 1, date ) );" )
<< QStringLiteral( "2010.01.05 11:10:32" );
QLocale locale = QLocale::system();
QDate date( 2010, 1, 5 );
QTest::newRow("2")
<< QStringLiteral( "ret = app.alert( util.printd( 2, date ) );" )
<< QString( date.toString( locale.dateFormat( QLocale::ShortFormat ) ) + QStringLiteral( " 11:10:32" ) );
<< QString( date.toString( locale.dateFormat( QLocale::ShortFormat ) ) + QStringLiteral( " 11:10:32 AM" ) );
}
void KJSFunctionsTest::testPrintD()
......
......@@ -70,6 +70,7 @@ static KJSObject printd( KJSContext *context, void *,
KJSObject oFormat = arguments.at( 0 );
QString format;
QLocale defaultLocale;
if( oFormat.isNumber() )
{
......@@ -83,8 +84,9 @@ static KJSObject printd( KJSContext *context, void *,
format = QStringLiteral( "yyyy.MM.dd HH:mm:ss");
break;
case 2:
QLocale system = QLocale::system();
format = system.dateTimeFormat( QLocale::ShortFormat ) + QStringLiteral( ":ss" );
format = defaultLocale.dateTimeFormat( QLocale::ShortFormat );
if( !format.contains( QStringLiteral( "ss" ) ) )
format.insert( format.indexOf( QStringLiteral( "mm" ) ) + 2, QStringLiteral( ":ss" ) );
break;
}
}
......@@ -107,7 +109,6 @@ static KJSObject printd( KJSContext *context, void *,
arg( str[2] ).arg( str[3] ).arg( str[4] ).arg( str[5] ).arg( str[6] );
QDateTime date = locale.toDateTime( myStr, QStringLiteral( "MMM/d/yyyy H:m:s" ) );
QLocale defaultLocale;
return KJSString( defaultLocale.toString( date, format ) );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment