• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kaddressbook

dateparser.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KAddressbook.
00003     Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 
00025 #include "dateparser.h"
00026 
00027 DateParser::DateParser( const QString &pattern )
00028   : mPattern( pattern )
00029 {
00030 }
00031 
00032 DateParser::~DateParser()
00033 {
00034 }
00035 
00036 QDate DateParser::parse( const QString &dateStr ) const
00037 {
00038   int year, month, day;
00039   year = month = day = 0;
00040 
00041   int currPos = 0;
00042   for ( int i = 0; i < mPattern.length(); ++i ) {
00043     if ( mPattern[ i ] == 'y' ) { // 19YY
00044       if ( currPos + 1 < dateStr.length() ) {
00045         year = 1900 + dateStr.mid( currPos, 2 ).toInt();
00046         currPos += 2;
00047       } else
00048         return QDate();
00049     } else if ( mPattern[ i ] == 'Y' ) { // YYYY
00050       if ( currPos + 3 < dateStr.length() ) {
00051         year = dateStr.mid( currPos, 4 ).toInt();
00052         currPos += 4;
00053       } else
00054         return QDate();
00055     } else if ( mPattern[ i ] == 'm' ) { // M or MM
00056       if ( currPos + 1 < dateStr.length() ) {
00057         if ( dateStr[ currPos ].isDigit() ) {
00058           if ( dateStr[ currPos + 1 ].isDigit() ) {
00059             month = dateStr.mid( currPos, 2 ).toInt();
00060             currPos += 2;
00061             continue;
00062           }
00063         }
00064       }
00065       if ( currPos < dateStr.length() ) {
00066         if ( dateStr[ currPos ].isDigit() ) {
00067           month = dateStr.mid( currPos, 1 ).toInt();
00068           currPos++;
00069           continue;
00070         }
00071       }
00072 
00073       return QDate();
00074     } else if ( mPattern[ i ] == 'M' ) { // 0M or MM
00075       if ( currPos + 1 < dateStr.length() ) {
00076         month = dateStr.mid( currPos, 2 ).toInt();
00077         currPos += 2;
00078       } else
00079         return QDate();
00080     } else if ( mPattern[ i ] == 'd' ) { // D or DD
00081       if ( currPos + 1 < dateStr.length() ) {
00082         if ( dateStr[ currPos ].isDigit() ) {
00083           if ( dateStr[ currPos + 1 ].isDigit() ) {
00084             day = dateStr.mid( currPos, 2 ).toInt();
00085             currPos += 2;
00086             continue;
00087           }
00088         }
00089       }
00090       if ( currPos < dateStr.length() ) {
00091         if ( dateStr[ currPos ].isDigit() ) {
00092           day = dateStr.mid( currPos, 1 ).toInt();
00093           currPos++;
00094           continue;
00095         }
00096       }
00097 
00098       return QDate();
00099     } else if ( mPattern[ i ] == 'D' ) { // 0D or DD
00100       if ( currPos + 1 < dateStr.length() ) {
00101         day = dateStr.mid( currPos, 2 ).toInt();
00102         currPos += 2;
00103       } else
00104         return QDate();
00105     } else {
00106       currPos++;
00107     }
00108   }
00109 
00110   return QDate( year, month, day );
00111 }

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal