qwt_date.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef _QWT_DATE_H_
  10. #define _QWT_DATE_H_
  11. #include "qwt_global.h"
  12. #include <qdatetime.h>
  13. /*!
  14. \brief A collection of methods around date/time values
  15. Qt offers convenient classes for dealing with date/time values,
  16. but Qwt uses coordinate systems that are based on doubles.
  17. QwtDate offers methods to translate from QDateTime to double and v.v.
  18. A double is interpreted as the number of milliseconds since
  19. 1970-01-01T00:00:00 Universal Coordinated Time - also known
  20. as "The Epoch".
  21. While the range of the Julian day in Qt4 is limited to [0, MAX_INT],
  22. Qt5 stores it as qint64 offering a huge range of valid dates.
  23. As the significance of a double is below this ( assuming a
  24. fraction of 52 bits ) the translation is not
  25. bijective with rounding errors for dates very far from Epoch.
  26. For a resolution of 1 ms those start to happen for dates above the
  27. year 144683.
  28. An axis for a date/time interval is expected to be aligned
  29. and divided in time/date units like seconds, minutes, ...
  30. QwtDate offers several algorithms that are needed to
  31. calculate these axes.
  32. \sa QwtDateScaleEngine, QwtDateScaleDraw, QDate, QTime
  33. */
  34. class QWT_EXPORT QwtDate
  35. {
  36. public:
  37. /*!
  38. How to identify the first week of year differs between
  39. countries.
  40. */
  41. enum Week0Type
  42. {
  43. /*!
  44. According to ISO 8601 the first week of a year is defined
  45. as "the week with the year's first Thursday in it".
  46. FirstThursday corresponds to the numbering that is
  47. implemented in QDate::weekNumber().
  48. */
  49. FirstThursday,
  50. /*!
  51. "The week with January 1.1 in it."
  52. In the U.S. this definition is more common than
  53. FirstThursday.
  54. */
  55. FirstDay
  56. };
  57. /*!
  58. Classification of an time interval
  59. Time intervals needs to be classified to decide how to
  60. align and divide it.
  61. */
  62. enum IntervalType
  63. {
  64. //! The interval is related to milliseconds
  65. Millisecond,
  66. //! The interval is related to seconds
  67. Second,
  68. //! The interval is related to minutes
  69. Minute,
  70. //! The interval is related to hours
  71. Hour,
  72. //! The interval is related to days
  73. Day,
  74. //! The interval is related to weeks
  75. Week,
  76. //! The interval is related to months
  77. Month,
  78. //! The interval is related to years
  79. Year
  80. };
  81. enum
  82. {
  83. //! The Julian day of "The Epoch"
  84. JulianDayForEpoch = 2440588
  85. };
  86. static QDate minDate();
  87. static QDate maxDate();
  88. static QDateTime toDateTime( double value,
  89. Qt::TimeSpec = Qt::UTC );
  90. static double toDouble( const QDateTime & );
  91. static QDateTime ceil( const QDateTime &, IntervalType );
  92. static QDateTime floor( const QDateTime &, IntervalType );
  93. static QDate dateOfWeek0( int year, Week0Type );
  94. static int weekNumber( const QDate &, Week0Type );
  95. static int utcOffset( const QDateTime & );
  96. static QString toString( const QDateTime &,
  97. const QString & format, Week0Type );
  98. };
  99. #endif