MythTV  master
mythdate.h
Go to the documentation of this file.
1 #ifndef MYTH_DATE_H
2 #define MYTH_DATE_H
3 
4 #include <cstdint>
5 
6 #include <QDateTime>
7 #include <QString>
8 
9 #include "mythbaseexp.h"
10 #include "mythchrono.h"
11 
12 namespace MythDate
13 {
14 
15 enum Format
16 {
18  kFilename = 0x000100,
19  kDateFull = 0x000200,
20  kDateShort = 0x000400,
22  kTime = 0x000800,
25  kAddYear = 0x001000,
26  kSimplify = 0x002000,
27  kDatabase = 0x004000,
28  kAutoYear = 0x008000,
29  kScreenShotFilename = 0x010000,
30  kRFC822 = 0x020000,
31  kOverrideUTC = 0x100000,
32  kOverrideLocal = 0x200000,
33 };
34 
37 MBASE_PUBLIC QDateTime current(bool stripped = false);
40 MBASE_PUBLIC QString current_iso_string(bool stripped = false);
42 MBASE_PUBLIC QDateTime as_utc(const QDateTime &dt);
43 
45 MBASE_PUBLIC QDateTime fromString(const QString &dtstr);
47 MBASE_PUBLIC QDateTime fromString(const QString &dt, const QString &format);
48 MBASE_PUBLIC QDateTime fromSecsSinceEpoch(int64_t seconds);
50 MBASE_PUBLIC QString toString(
51  const QDateTime &datetime, uint format = MythDate::kDateTimeFull);
53 MBASE_PUBLIC QString toString(
54  QDate date, uint format = MythDate::kDateFull);
55 
56 // Returns the total number of seconds since midnight
57 MBASE_PUBLIC std::chrono::seconds toSeconds( QTime time );
58 
59 MBASE_PUBLIC std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void);
60 MBASE_PUBLIC std::chrono::seconds secsInPast (const QDateTime& past);
61 MBASE_PUBLIC std::chrono::seconds secsInFuture (const QDateTime& future);
62 
63 MBASE_PUBLIC QString formatTime(std::chrono::milliseconds msecs,
64  QString fmt = "HH:mm:ss");
65 
66 } // namespace MythDate
67 
76 inline int ternary_compare(const QDateTime& a, const QDateTime& b)
77 {
78  if (a < b) return -1;
79  if (a > b) return +1;
80  return 0; // a == b
81 }
82 
83 #endif // MYTH_DATE_H
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
MythDate::as_utc
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:28
mythbaseexp.h
MythDate::kScreenShotFilename
@ kScreenShotFilename
"yyyy-MM-ddThh-mm-ss.zzz"
Definition: mythdate.h:29
MythDate::kOverrideUTC
@ kOverrideUTC
Present date/time in UTC.
Definition: mythdate.h:31
MythDate::formatTime
QString formatTime(std::chrono::milliseconds msecs, QString fmt)
Format a milliseconds time value.
Definition: mythdate.cpp:242
MythDate::Format
Format
Definition: mythdate.h:15
MythDate::kDateTimeShort
@ kDateTimeShort
Default local time.
Definition: mythdate.h:24
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
MythDate::secsInFuture
std::chrono::seconds secsInFuture(const QDateTime &future)
Definition: mythdate.cpp:217
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythDate::fromSecsSinceEpoch
MBASE_PUBLIC QDateTime fromSecsSinceEpoch(int64_t seconds)
This function takes the number of seconds since the start of the epoch and returns a QDateTime with t...
Definition: mythdate.cpp:81
MythDate::kFilename
@ kFilename
Default UTC, "yyyyMMddhhmmss".
Definition: mythdate.h:18
MythDate::kDateEither
@ kDateEither
Default local time.
Definition: mythdate.h:21
MythDate::kOverrideLocal
@ kOverrideLocal
Present date/time in localtime.
Definition: mythdate.h:32
MythDate::kAutoYear
@ kAutoYear
Add year only if different from current year.
Definition: mythdate.h:28
MythDate::kDateShort
@ kDateShort
Default local time.
Definition: mythdate.h:20
ternary_compare
int ternary_compare(const QDateTime &a, const QDateTime &b)
balanced ternary (three way) comparison This is equivalent to C++20's operator <=>.
Definition: mythdate.h:76
MythDate::fromString
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
MythDate::kSimplify
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:26
MythDate::currentMSecsSinceEpochAsDuration
std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void)
Definition: mythdate.cpp:207
MythDate::secsInPast
std::chrono::seconds secsInPast(const QDateTime &past)
Definition: mythdate.cpp:212
MythDate::kAddYear
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:25
MythDate::kRFC822
@ kRFC822
HTTP Date format.
Definition: mythdate.h:30
MythDate
Definition: mythdate.cpp:12
MythDate::ISODate
@ ISODate
Default UTC.
Definition: mythdate.h:17
mythchrono.h
MythDate::current_iso_string
QString current_iso_string(bool stripped)
Returns current Date and Time in UTC as a string.
Definition: mythdate.cpp:23
MythDate::kDatabase
@ kDatabase
Default UTC, database format.
Definition: mythdate.h:27
MythDate::kDateFull
@ kDateFull
Default local time.
Definition: mythdate.h:19
MythDate::toSeconds
std::chrono::seconds toSeconds(QTime time)
Returns the total number of seconds since midnight of the supplied QTime.
Definition: mythdate.cpp:195
MythDate::kDateTimeFull
@ kDateTimeFull
Default local time.
Definition: mythdate.h:23
MythDate::kTime
@ kTime
Default local time.
Definition: mythdate.h:22
uint
unsigned int uint
Definition: freesurround.h:24