24 #include <tqdatetime.h>
26 #include "dateparser.h"
28 DateParser::DateParser(
const TQString &pattern )
33 DateParser::~DateParser()
37 TQDate DateParser::parse(
const TQString &dateStr )
const
40 year = month = day = 0;
43 for ( uint i = 0; i < mPattern.length(); ++i ) {
44 if ( mPattern[ i ] ==
'y' ) {
45 if ( currPos + 1 < dateStr.length() ) {
46 year = 1900 + dateStr.mid( currPos, 2 ).toInt();
50 }
else if ( mPattern[ i ] ==
'Y' ) {
51 if ( currPos + 3 < dateStr.length() ) {
52 year = dateStr.mid( currPos, 4 ).toInt();
56 }
else if ( mPattern[ i ] ==
'm' ) {
57 if ( currPos + 1 < dateStr.length() ) {
58 if ( dateStr[ currPos ].isDigit() ) {
59 if ( dateStr[ currPos + 1 ].isDigit() ) {
60 month = dateStr.mid( currPos, 2 ).toInt();
66 if ( currPos < dateStr.length() ) {
67 if ( dateStr[ currPos ].isDigit() ) {
68 month = dateStr.mid( currPos, 1 ).toInt();
75 }
else if ( mPattern[ i ] ==
'M' ) {
76 if ( currPos + 1 < dateStr.length() ) {
77 month = dateStr.mid( currPos, 2 ).toInt();
81 }
else if ( mPattern[ i ] ==
'd' ) {
82 if ( currPos + 1 < dateStr.length() ) {
83 if ( dateStr[ currPos ].isDigit() ) {
84 if ( dateStr[ currPos + 1 ].isDigit() ) {
85 day = dateStr.mid( currPos, 2 ).toInt();
91 if ( currPos < dateStr.length() ) {
92 if ( dateStr[ currPos ].isDigit() ) {
93 day = dateStr.mid( currPos, 1 ).toInt();
100 }
else if ( mPattern[ i ] ==
'D' ) {
101 if ( currPos + 1 < dateStr.length() ) {
102 day = dateStr.mid( currPos, 2 ).toInt();
111 return TQDate( year, month, day );