qt_demoe/third/3rd_qwt/qwt_date.h

129 lines
3.4 KiB
C
Raw Normal View History

2019-11-07 02:55:57 +00:00
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#ifndef _QWT_DATE_H_
#define _QWT_DATE_H_
#include "qwt_global.h"
#include <qdatetime.h>
/*!
\brief A collection of methods around date/time values
Qt offers convenient classes for dealing with date/time values,
but Qwt uses coordinate systems that are based on doubles.
QwtDate offers methods to translate from QDateTime to double and v.v.
A double is interpreted as the number of milliseconds since
1970-01-01T00:00:00 Universal Coordinated Time - also known
2021-10-08 02:51:37 +00:00
as "The Epoch".
2019-11-07 02:55:57 +00:00
2021-10-08 02:51:37 +00:00
While the range of the Julian day in Qt4 is limited to [0, MAX_INT],
Qt5 stores it as qint64 offering a huge range of valid dates.
As the significance of a double is below this ( assuming a
fraction of 52 bits ) the translation is not
bijective with rounding errors for dates very far from Epoch.
For a resolution of 1 ms those start to happen for dates above the
year 144683.
2019-11-07 02:55:57 +00:00
An axis for a date/time interval is expected to be aligned
and divided in time/date units like seconds, minutes, ...
QwtDate offers several algorithms that are needed to
calculate these axes.
\sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime
*/
class QWT_EXPORT QwtDate
{
public:
2021-10-08 02:51:37 +00:00
/*!
2019-11-07 02:55:57 +00:00
How to identify the first week of year differs between
2021-10-08 02:51:37 +00:00
countries.
2019-11-07 02:55:57 +00:00
*/
enum Week0Type
{
/*!
According to ISO 8601 the first week of a year is defined
as "the week with the year's first Thursday in it".
FirstThursday corresponds to the numbering that is
implemented in QDate::weekNumber().
*/
FirstThursday,
/*!
"The week with January 1.1 in it."
2021-10-08 02:51:37 +00:00
2019-11-07 02:55:57 +00:00
In the U.S. this definition is more common than
FirstThursday.
*/
FirstDay
};
2021-10-08 02:51:37 +00:00
/*!
2019-11-07 02:55:57 +00:00
Classification of an time interval
Time intervals needs to be classified to decide how to
align and divide it.
*/
enum IntervalType
{
//! The interval is related to milliseconds
Millisecond,
//! The interval is related to seconds
Second,
//! The interval is related to minutes
Minute,
//! The interval is related to hours
Hour,
//! The interval is related to days
Day,
//! The interval is related to weeks
Week,
//! The interval is related to months
Month,
//! The interval is related to years
Year
};
enum
{
//! The Julian day of "The Epoch"
JulianDayForEpoch = 2440588
};
static QDate minDate();
static QDate maxDate();
2021-10-08 02:51:37 +00:00
static QDateTime toDateTime( double value,
2019-11-07 02:55:57 +00:00
Qt::TimeSpec = Qt::UTC );
static double toDouble( const QDateTime & );
static QDateTime ceil( const QDateTime &, IntervalType );
static QDateTime floor( const QDateTime &, IntervalType );
static QDate dateOfWeek0( int year, Week0Type );
static int weekNumber( const QDate &, Week0Type );
static int utcOffset( const QDateTime & );
2021-10-08 02:51:37 +00:00
static QString toString( const QDateTime &,
2019-11-07 02:55:57 +00:00
const QString & format, Week0Type );
};
#endif