2017-10-03 04:05:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-03 04:05:23 -05:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-03 04:05:23 -05:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-10-03 04:05:23 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-10-03 06:54:07 -05:00
|
|
|
#include <QDateTime>
|
2019-09-06 03:40:57 -05:00
|
|
|
#include <QString>
|
|
|
|
#include <string>
|
2017-10-03 04:05:23 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-10-03 04:05:23 -05:00
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
class RiaDateStringParser
|
|
|
|
{
|
|
|
|
public:
|
2023-01-13 06:04:44 -06:00
|
|
|
enum class OrderPreference
|
|
|
|
{
|
|
|
|
YEAR_FIRST,
|
|
|
|
DAY_FIRST
|
|
|
|
};
|
|
|
|
|
|
|
|
static QDateTime parseDateString( const QString& dateString, OrderPreference preference = OrderPreference::YEAR_FIRST );
|
2023-02-26 03:48:40 -06:00
|
|
|
static QDateTime parseDateString( const std::string& dateStringString, OrderPreference preference = OrderPreference::YEAR_FIRST );
|
2017-10-03 04:05:23 -05:00
|
|
|
|
|
|
|
private:
|
2023-02-26 03:48:40 -06:00
|
|
|
static bool parseDateStringWithSeparators( const std::string& dateString, int& year, int& month, int& day, OrderPreference preference );
|
2023-01-13 06:04:44 -06:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
static bool parseDateStringWithoutSeparators( const std::string& dateString, int& year, int& month, int& day, OrderPreference preference );
|
2023-01-13 06:04:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static bool tryParseYearFirst( const std::string& s, int& year, int& month, int& day );
|
|
|
|
static bool tryParseDayFirst( const std::string& s, int& year, int& month, int& day );
|
|
|
|
static bool tryParseMonthFirst( const std::string& s, int& year, int& month, int& day );
|
2017-10-03 04:05:23 -05:00
|
|
|
|
2020-01-21 08:14:17 -06:00
|
|
|
static bool tryParseYearFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
|
|
|
static bool tryParseDayFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
|
|
|
static bool tryParseMonthFirstNoSeparators( const std::string& s, int& year, int& month, int& day );
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static bool tryParseYear( const std::string& s, int& year );
|
|
|
|
static bool tryParseMonth( const std::string& s, int& month );
|
|
|
|
static bool tryParseDay( const std::string& s, int& day );
|
2017-10-03 04:05:23 -05:00
|
|
|
|
2020-01-21 08:14:17 -06:00
|
|
|
static std::string separators();
|
|
|
|
static bool hasSeparators( const std::string& s );
|
2019-09-06 03:40:57 -05:00
|
|
|
static std::string trimString( const std::string& s );
|
2017-10-03 04:05:23 -05:00
|
|
|
};
|