From: Jason Harris Date: Wed, 2 Nov 2005 06:23:51 +0000 (+0000) Subject: Some obscure fixes related to setting the clock on startup: X-Git-Tag: v3.5.0^0 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=5449da8bf81d08288931e1d3b8180f032a502b06;p=libqmvoc.git Some obscure fixes related to setting the clock on startup: + Make the ExtDate::fromString() function les picky about what date formats it accepts. + When setting the date from a script which is run from the command line, make sure to set the given time as the local time, not the UT. + Make sure focus position specified in a script is persistent if the script is run from the command line. Will forward port to trunk. Thanks to Yannick Gingras for the bug report! CCMAIL: kstars-devel@kde.org CCMAIL: ygingras@ygingras.net svn path=/branches/KDE/3.5/kdeedu/libkdeedu/; revision=476798 --- diff --git a/extdate/extdatetime.cpp b/extdate/extdatetime.cpp index 66f3243..6b548bc 100644 --- a/extdate/extdatetime.cpp +++ b/extdate/extdatetime.cpp @@ -356,6 +356,17 @@ ExtDate ExtDate::currentDate(Qt::TimeSpec ts) } #ifndef QT_NO_DATESTRING +//Try both DateFormat values +ExtDate ExtDate::fromString( const QString& s ) +{ + ExtDate dResult = ExtDate::fromString( s, Qt::TextDate ); + if ( dResult.isValid() ) return dResult; + + dResult = ExtDate::fromString( s, Qt::ISODate ); + if ( dResult.isValid() ) return dResult; + else return ExtDate(); //invalid +} + ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f ) { ExtDate dt = ExtDate(); //initialize invalid date @@ -373,6 +384,7 @@ ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f ) int year( s.mid( 0, 4 ).toInt() ); int month( s.mid( 5, 2 ).toInt() ); int day( s.mid( 8, 2 ).toInt() ); + if ( year && month && day ) return ExtDate( year, month, day ); } @@ -384,6 +396,7 @@ ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f ) { //Three possible date formats: //dd mth yyyy; mth dd yyyy; wkd mth dd yyyy + //"mth" is the word for the month (long or short form) QStringList ss = QStringList::split( " ", s ); bool ok = false; int month = -1; @@ -412,7 +425,7 @@ ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f ) } for ( uint i = 0; i < 12; i++ ) { - if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) { + if ( ss[imonth] == shortMonthName( i+1 ) || ss[imonth] == longMonthName( i+1 ) ) { month = i + 1; break; } @@ -422,7 +435,7 @@ ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f ) imonth = 2; iyear = 3; for ( uint i = 0; i < 12; i++ ) { - if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) { + if ( ss[imonth] == shortMonthName( i+1 ) || ss[imonth] == longMonthName( i+1 ) ) { month = i + 1; break; } @@ -1002,6 +1015,17 @@ ExtDateTime ExtDateTime::currentDateTime( Qt::TimeSpec ts ) \warning Note that \c Qt::LocalDate cannot be used here. */ +ExtDateTime ExtDateTime::fromString( const QString& s ) +{ + ExtDateTime dtResult = ExtDateTime::fromString( s, Qt::TextDate ); + if ( dtResult.isValid() ) return dtResult; + + dtResult = ExtDateTime::fromString( s, Qt::ISODate ); + + if ( dtResult.isValid() ) return dtResult; + else return ExtDateTime(); //invalid +} + ExtDateTime ExtDateTime::fromString( const QString& s, Qt::DateFormat f ) { ExtDateTime dt; @@ -1015,8 +1039,13 @@ ExtDateTime ExtDateTime::fromString( const QString& s, Qt::DateFormat f ) } if ( f == Qt::ISODate ) { - return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ), + if ( s.length() <= 10 || ! s.contains( ':' ) ) { //no time specified + QTime t = QTime(0,0,0); + return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ) ); + } else { + return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ), QTime::fromString( s.mid(11), Qt::ISODate ) ); + } } #if !defined(QT_NO_REGEXP) && !defined(QT_NO_TEXTDATE) else if ( f == Qt::TextDate ) { diff --git a/extdate/extdatetime.h b/extdate/extdatetime.h index 8193f76..bdc4c11 100644 --- a/extdate/extdatetime.h +++ b/extdate/extdatetime.h @@ -90,7 +90,8 @@ public: static ExtDate currentDate( Qt::TimeSpec ts = Qt::LocalTime ); #ifndef QT_NO_DATESTRING - static ExtDate fromString( const QString& s, Qt::DateFormat f = Qt::TextDate ); + static ExtDate fromString( const QString &s ); + static ExtDate fromString( const QString &s, Qt::DateFormat f ); #endif static bool isValid( int y, int m, int d ); static bool leapYear( int year ); @@ -164,7 +165,8 @@ public: static ExtDateTime currentDateTime(); static ExtDateTime currentDateTime( Qt::TimeSpec ); #ifndef QT_NO_DATESTRING - static ExtDateTime fromString( const QString& s, Qt::DateFormat f = Qt::TextDate ); + static ExtDateTime fromString( const QString &s ); + static ExtDateTime fromString( const QString &s, Qt::DateFormat f ); #endif private: ExtDate d;