33 int year, month, day, hour, minute, second;
34 year = month = day = hour = minute = second = 0;
37 for (
int i = 0; i < mPattern.length(); ++i ) {
38 if ( mPattern[ i ] == QLatin1Char(
'y') ) {
39 if ( currPos + 1 < dateStr.length() ) {
40 year = 1900 + dateStr.mid( currPos, 2 ).toInt();
45 }
else if ( mPattern[ i ] == QLatin1Char(
'Y') ) {
46 if ( currPos + 3 < dateStr.length() ) {
47 year = dateStr.mid( currPos, 4 ).toInt();
52 }
else if ( mPattern[ i ] == QLatin1Char(
'm') ) {
53 if ( currPos + 1 < dateStr.length() ) {
54 if ( dateStr[ currPos ].isDigit() ) {
55 if ( dateStr[ currPos + 1 ].isDigit() ) {
56 month = dateStr.mid( currPos, 2 ).toInt();
62 if ( currPos < dateStr.length() ) {
63 if ( dateStr[ currPos ].isDigit() ) {
64 month = dateStr.mid( currPos, 1 ).toInt();
71 }
else if ( mPattern[ i ] == QLatin1Char(
'M') ) {
72 if ( currPos + 1 < dateStr.length() ) {
73 month = dateStr.mid( currPos, 2 ).toInt();
78 }
else if ( mPattern[ i ] == QLatin1Char(
'd') ) {
79 if ( currPos + 1 < dateStr.length() ) {
80 if ( dateStr[ currPos ].isDigit() ) {
81 if ( dateStr[ currPos + 1 ].isDigit() ) {
82 day = dateStr.mid( currPos, 2 ).toInt();
88 if ( currPos < dateStr.length() ) {
89 if ( dateStr[ currPos ].isDigit() ) {
90 day = dateStr.mid( currPos, 1 ).toInt();
97 }
else if ( mPattern[ i ] == QLatin1Char(
'D') ) {
98 if ( currPos + 1 < dateStr.length() ) {
99 day = dateStr.mid( currPos, 2 ).toInt();
104 }
else if ( mPattern[ i ] == QLatin1Char(
'H') ) {
105 if ( currPos + 1 < dateStr.length() ) {
106 hour = dateStr.mid( currPos, 2 ).toInt();
111 }
else if ( mPattern[ i ] == QLatin1Char(
'I') ) {
112 if ( currPos + 1 < dateStr.length() ) {
113 minute = dateStr.mid( currPos, 2 ).toInt();
118 }
else if ( mPattern[ i ] == QLatin1Char(
'S') ) {
119 if ( currPos + 1 < dateStr.length() ) {
120 second = dateStr.mid( currPos, 2 ).toInt();
130 return QDateTime( QDate( year, month, day ), QTime( hour, minute, second ) );
QDateTime parse(const QString &dateStr) const
DateParser(const QString &pattern)