2017-09-28 01:04:27 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-09-28 01:04:27 -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-09-28 01:04:27 -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-09-28 01:04:27 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-03-14 03:18:48 -05:00
|
|
|
#include "RiaDateTimeDefines.h"
|
|
|
|
|
|
|
|
#include "cafAppEnum.h"
|
|
|
|
|
2018-06-20 02:41:01 -05:00
|
|
|
#include <QString>
|
|
|
|
|
2017-09-28 01:04:27 -05:00
|
|
|
#include <string>
|
2018-06-20 02:41:01 -05:00
|
|
|
#include <vector>
|
2017-09-28 01:04:27 -05:00
|
|
|
|
2017-10-03 07:03:23 -05:00
|
|
|
class QDateTime;
|
2017-10-09 06:03:42 -05:00
|
|
|
class QDate;
|
|
|
|
class QTime;
|
2018-06-12 04:04:36 -05:00
|
|
|
class DateTimeSpan;
|
|
|
|
|
2020-03-29 06:49:55 -05:00
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
class PdmOptionItemInfo;
|
|
|
|
};
|
|
|
|
|
2017-09-28 01:04:27 -05:00
|
|
|
//==================================================================================================
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-09-28 01:04:27 -05:00
|
|
|
//==================================================================================================
|
2017-10-03 07:03:23 -05:00
|
|
|
class RiaQDateTimeTools
|
2017-09-28 01:04:27 -05:00
|
|
|
{
|
|
|
|
public:
|
2017-10-09 06:03:42 -05:00
|
|
|
static Qt::TimeSpec currentTimeSpec();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static QDateTime fromString( const QString& dateString, const QString& format );
|
|
|
|
static QDateTime fromYears( double years );
|
|
|
|
static QDateTime fromTime_t( time_t t );
|
2018-06-12 04:04:36 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static QDateTime addMSecs( const QDateTime& dt, double msecs );
|
|
|
|
static QDateTime addDays( const QDateTime& dt, double days );
|
|
|
|
static QDateTime addYears( const QDateTime& dt, double years );
|
|
|
|
static QDateTime addSpan( const QDateTime& dt, DateTimeSpan span );
|
|
|
|
static QDateTime subtractSpan( const QDateTime& dt, DateTimeSpan span );
|
2022-03-14 03:18:48 -05:00
|
|
|
static QDateTime addPeriod( const QDateTime& dt, RiaDefines::DateTimePeriod period );
|
|
|
|
static QDateTime subtractPeriod( const QDateTime& dt, RiaDefines::DateTimePeriod period );
|
2017-09-28 01:04:27 -05:00
|
|
|
|
2022-03-11 06:24:01 -06:00
|
|
|
static QDateTime createDateTime( const QDate& date );
|
|
|
|
|
2017-10-03 07:03:23 -05:00
|
|
|
static QDateTime epoch();
|
2017-09-28 01:04:27 -05:00
|
|
|
|
2017-10-13 09:54:04 -05:00
|
|
|
static QDateTime createUtcDateTime();
|
2019-09-06 03:40:57 -05:00
|
|
|
static QDateTime createUtcDateTime( const QDate& date );
|
|
|
|
static QDateTime createUtcDateTime( const QDate& date, const QTime& time );
|
|
|
|
static QDateTime createUtcDateTime( const QDateTime& dt );
|
2018-06-12 04:04:36 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static bool lessThan( const QDateTime& dt1, const QDateTime& dt2 );
|
2018-06-12 04:04:36 -05:00
|
|
|
|
2022-03-14 03:18:48 -05:00
|
|
|
static const DateTimeSpan timeSpan( RiaDefines::DateTimePeriod period );
|
|
|
|
static QDateTime truncateTime( const QDateTime& dt, RiaDefines::DateTimePeriod period );
|
2017-10-09 06:03:42 -05:00
|
|
|
|
2022-03-14 03:18:48 -05:00
|
|
|
static std::vector<RiaDefines::DateTimePeriod> dateTimePeriods();
|
|
|
|
static QString dateTimePeriodName( RiaDefines::DateTimePeriod period );
|
2018-06-20 02:41:01 -05:00
|
|
|
|
2018-10-01 03:19:59 -05:00
|
|
|
// This function uses C locale to make sure the text representation of a date is stable, independent of the locale
|
|
|
|
// settings on local machine. Required for stable regression testing.
|
2019-09-06 03:40:57 -05:00
|
|
|
static QString toStringUsingApplicationLocale( const QDateTime& dt, const QString& format );
|
2018-10-01 03:19:59 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static QString createTimeFormatStringFromDates( const std::vector<QDateTime>& dates );
|
2019-02-27 04:38:35 -06:00
|
|
|
static QString dateFormatString();
|
|
|
|
|
2019-08-19 02:37:42 -05:00
|
|
|
static std::vector<QString> supportedDateFormats();
|
|
|
|
static std::vector<QString> supportedTimeFormats();
|
|
|
|
|
2022-03-14 03:18:48 -05:00
|
|
|
static QString dateFormatString(
|
|
|
|
const QString& fullDateFormat,
|
|
|
|
RiaDefines::DateFormatComponents dateComponents = RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
|
|
|
static QString timeFormatString( const QString& fullTimeFormat,
|
|
|
|
RiaDefines::TimeFormatComponents timeComponents =
|
|
|
|
RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE_SECOND );
|
2019-08-19 02:37:42 -05:00
|
|
|
|
2020-03-29 06:49:55 -05:00
|
|
|
static QList<caf::PdmOptionItemInfo> createOptionItems( const std::vector<time_t>& timeSteps );
|
|
|
|
|
2017-09-28 01:04:27 -05:00
|
|
|
private:
|
2022-03-14 03:18:48 -05:00
|
|
|
static const DateTimeSpan TIMESPAN_DAY;
|
|
|
|
static const DateTimeSpan TIMESPAN_WEEK;
|
|
|
|
static const DateTimeSpan TIMESPAN_MONTH;
|
|
|
|
static const DateTimeSpan TIMESPAN_QUARTER;
|
|
|
|
static const DateTimeSpan TIMESPAN_HALFYEAR;
|
|
|
|
static const DateTimeSpan TIMESPAN_YEAR;
|
|
|
|
static const DateTimeSpan TIMESPAN_DECADE;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static quint64 secondsInDay();
|
|
|
|
static quint64 secondsInYear();
|
2017-09-28 01:04:27 -05:00
|
|
|
};
|
2018-06-12 04:04:36 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-06-12 04:04:36 -05:00
|
|
|
//==================================================================================================
|
|
|
|
class DateTimeSpan
|
|
|
|
{
|
|
|
|
public:
|
2019-09-06 03:40:57 -05:00
|
|
|
DateTimeSpan()
|
|
|
|
: m_years( 0 )
|
|
|
|
, m_months( 0 )
|
|
|
|
, m_days( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
DateTimeSpan( int years, int months, int days )
|
|
|
|
: m_years( years )
|
|
|
|
, m_months( months )
|
|
|
|
, m_days( days )
|
|
|
|
{
|
|
|
|
}
|
2018-06-12 04:04:36 -05:00
|
|
|
|
2020-02-12 04:13:38 -06:00
|
|
|
int years() const { return m_years; }
|
|
|
|
int months() const { return m_months; }
|
|
|
|
int days() const { return m_days; }
|
2018-06-12 04:04:36 -05:00
|
|
|
|
2020-02-12 04:13:38 -06:00
|
|
|
bool isEmpty() { return m_years == 0 && m_months == 0 && m_days; }
|
2018-06-12 04:04:36 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_years;
|
|
|
|
int m_months;
|
|
|
|
int m_days;
|
|
|
|
};
|