File indexing completed on 2024-04-28 05:50:09

0001 /*
0002  * SPDX-License-Identifier: GPL-3.0-or-later
0003  * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
0004  */
0005 
0006 #ifndef DATETIME_VALIDATOR_H
0007 #define DATETIME_VALIDATOR_H
0008 
0009 #include <QDateTime>
0010 #include <QLocale>
0011 #include <QValidator>
0012 
0013 #include <functional>
0014 #include <optional>
0015 
0016 namespace validators
0017 {
0018     std::optional<QDateTime> parseDateTime(const QString &input);
0019 
0020     class EpochValidator: public QValidator
0021     {
0022         Q_OBJECT
0023     public:
0024         explicit EpochValidator(const std::function<qint64(void)> clock = &QDateTime::currentMSecsSinceEpoch, QObject *parent = nullptr);
0025         void fixup(QString &input) const override;
0026         QValidator::State validate(QString &input, int &pos) const override;
0027     private:
0028         const std::function<qint64(void)> m_clock;
0029     };
0030 }
0031 
0032 #endif