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: ...@@ -333,6 +333,10 @@ private:
void KJSFunctionsTest::testPrintD_data() void KJSFunctionsTest::testPrintD_data()
{ {
// Force consistent locale
QLocale locale( QStringLiteral( "en_US" ) );
QLocale::setDefault( locale );
QTest::addColumn<QString>("script"); QTest::addColumn<QString>("script");
QTest::addColumn<QString>("result"); QTest::addColumn<QString>("result");
...@@ -359,11 +363,10 @@ void KJSFunctionsTest::testPrintD_data() ...@@ -359,11 +363,10 @@ void KJSFunctionsTest::testPrintD_data()
<< QStringLiteral( "ret = app.alert( util.printd( 1, date ) );" ) << QStringLiteral( "ret = app.alert( util.printd( 1, date ) );" )
<< QStringLiteral( "2010.01.05 11:10:32" ); << QStringLiteral( "2010.01.05 11:10:32" );
QLocale locale = QLocale::system();
QDate date( 2010, 1, 5 ); QDate date( 2010, 1, 5 );
QTest::newRow("2") QTest::newRow("2")
<< QStringLiteral( "ret = app.alert( util.printd( 2, date ) );" ) << 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() void KJSFunctionsTest::testPrintD()
......
...@@ -70,6 +70,7 @@ static KJSObject printd( KJSContext *context, void *, ...@@ -70,6 +70,7 @@ static KJSObject printd( KJSContext *context, void *,
KJSObject oFormat = arguments.at( 0 ); KJSObject oFormat = arguments.at( 0 );
QString format; QString format;
QLocale defaultLocale;
if( oFormat.isNumber() ) if( oFormat.isNumber() )
{ {
...@@ -83,8 +84,9 @@ static KJSObject printd( KJSContext *context, void *, ...@@ -83,8 +84,9 @@ static KJSObject printd( KJSContext *context, void *,
format = QStringLiteral( "yyyy.MM.dd HH:mm:ss"); format = QStringLiteral( "yyyy.MM.dd HH:mm:ss");
break; break;
case 2: case 2:
QLocale system = QLocale::system(); format = defaultLocale.dateTimeFormat( QLocale::ShortFormat );
format = system.dateTimeFormat( QLocale::ShortFormat ) + QStringLiteral( ":ss" ); if( !format.contains( QStringLiteral( "ss" ) ) )
format.insert( format.indexOf( QStringLiteral( "mm" ) ) + 2, QStringLiteral( ":ss" ) );
break; break;
} }
} }
...@@ -107,7 +109,6 @@ static KJSObject printd( KJSContext *context, void *, ...@@ -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] ); 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" ) ); QDateTime date = locale.toDateTime( myStr, QStringLiteral( "MMM/d/yyyy H:m:s" ) );
QLocale defaultLocale;
return KJSString( defaultLocale.toString( date, format ) ); 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