File indexing completed on 2024-04-28 16:13:25

0001 /*
0002     SPDX-FileCopyrightText: 2004 Ace Jones acejones @users.sourceforge.net
0003 
0004     This file is part of libalkimia.
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef ALKDATEFORMAT_H
0010 #define ALKDATEFORMAT_H
0011 
0012 #include "alkexception.h"
0013 
0014 #include <QDate>
0015 #include <QRegExp>
0016 #include <QString>
0017 #include <QStringList>
0018 
0019 /**
0020  *
0021  * Universal date converter
0022  *
0023  * In 'strict' mode, this is designed to be compatible with the QIF profile date
0024  * converter.  However, that converter deals with the concept of an apostrophe
0025  * format in a way I don't understand.  So for the moment, they are 99%
0026  * compatible, waiting on that issue. (acejones)
0027  */
0028 class ALK_NO_EXPORT AlkDateFormat
0029 {
0030 public:
0031     explicit AlkDateFormat(const QString &format);
0032     ~AlkDateFormat();
0033 
0034     AlkDateFormat& operator=(const AlkDateFormat&);
0035 
0036     typedef enum {
0037       NoError = 0,
0038       InvalidFormatString,
0039       InvalidFormatCharacter,
0040       InvalidDate,
0041       InvalidDay,
0042       InvalidMonth,
0043       InvalidYear,
0044       InvalidYearLength,
0045     } ErrorCode;
0046 
0047     QString convertDate(const QDate &date);
0048     QDate convertString(const QString &date, bool strict = true,
0049                               unsigned centuryMidPoint = QDate::currentDate().year());
0050     const QString &format() const;
0051 
0052     QString lastErrorMessage() const;
0053     ErrorCode lastError() const;
0054 
0055 private:
0056     class Private;
0057     Private* const d;
0058 };
0059 
0060 #endif // ALKDATEFORMAT_H