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 <QChar> // Fix Qt6 GCC SFINAE warning
7#include <QDateTime>
8#include <QString>
9
10#include "mythbaseexp.h"
11#include "mythchrono.h"
12
13namespace MythDate
14{
15
17{
19 kFilename = 0x000100,
20 kDateFull = 0x000200,
21 kDateShort = 0x000400,
23 kTime = 0x000800,
26 kAddYear = 0x001000,
27 kSimplify = 0x002000,
28 kDatabase = 0x004000,
29 kAutoYear = 0x008000,
31 kRFC822 = 0x020000,
32 kOverrideUTC = 0x100000,
33 kOverrideLocal = 0x200000,
34};
35
38MBASE_PUBLIC QDateTime current(bool stripped = false);
41MBASE_PUBLIC QString current_iso_string(bool stripped = false);
43MBASE_PUBLIC QDateTime as_utc(const QDateTime &dt);
44
46MBASE_PUBLIC QDateTime fromString(const QString &dtstr);
48MBASE_PUBLIC QDateTime fromString(const QString &dt, const QString &format);
49MBASE_PUBLIC QDateTime fromSecsSinceEpoch(int64_t seconds);
52 const QDateTime &datetime, uint format = MythDate::kDateTimeFull);
55 QDate date, uint format = MythDate::kDateFull);
56
57// Returns the total number of seconds since midnight
58MBASE_PUBLIC std::chrono::seconds toSeconds( QTime time );
59
60MBASE_PUBLIC std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void);
61MBASE_PUBLIC std::chrono::seconds secsInPast (const QDateTime& past);
62MBASE_PUBLIC std::chrono::seconds secsInFuture (const QDateTime& future);
63
64MBASE_PUBLIC QString formatTime(std::chrono::milliseconds msecs,
65 QString fmt = "HH:mm:ss");
66
67} // namespace MythDate
68
69#endif // MYTH_DATE_H
unsigned int uint
Definition: compat.h:60
#define MBASE_PUBLIC
Definition: mythbaseexp.h:8
QString current_iso_string(bool stripped)
Returns current Date and Time in UTC as a string.
Definition: mythdate.cpp:23
QString formatTime(std::chrono::milliseconds msecs, QString fmt)
Format a milliseconds time value.
Definition: mythdate.cpp:242
std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void)
Definition: mythdate.cpp:207
QDateTime as_utc(const QDateTime &old_dt)
Returns copy of QDateTime with TimeSpec set to UTC.
Definition: mythdate.cpp:28
std::chrono::seconds secsInPast(const QDateTime &past)
Definition: mythdate.cpp:212
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
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:93
@ kOverrideUTC
Present date/time in UTC.
Definition: mythdate.h:32
@ kScreenShotFilename
"yyyy-MM-ddThh-mm-ss.zzz"
Definition: mythdate.h:30
@ kDateTimeFull
Default local time.
Definition: mythdate.h:24
@ kFilename
Default UTC, "yyyyMMddhhmmss".
Definition: mythdate.h:19
@ kRFC822
HTTP Date format.
Definition: mythdate.h:31
@ kSimplify
Do Today/Yesterday/Tomorrow transform.
Definition: mythdate.h:27
@ kDateFull
Default local time.
Definition: mythdate.h:20
@ kDateTimeShort
Default local time.
Definition: mythdate.h:25
@ ISODate
Default UTC.
Definition: mythdate.h:18
@ kTime
Default local time.
Definition: mythdate.h:23
@ kAddYear
Add year to string if not included.
Definition: mythdate.h:26
@ kOverrideLocal
Present date/time in localtime.
Definition: mythdate.h:33
@ kDateEither
Default local time.
Definition: mythdate.h:22
@ kDateShort
Default local time.
Definition: mythdate.h:21
@ kDatabase
Default UTC, database format.
Definition: mythdate.h:28
@ kAutoYear
Add year only if different from current year.
Definition: mythdate.h:29
std::chrono::seconds secsInFuture(const QDateTime &future)
Definition: mythdate.cpp:217
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
std::chrono::seconds toSeconds(QTime time)
Returns the total number of seconds since midnight of the supplied QTime.
Definition: mythdate.cpp:195
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15