19
QSharedPointer<Clock> Clock::m_instance;
21
QDateTime Clock::currentDateTimeUtc()
23
return instance().currentDateTimeUtcImpl();
26
QDateTime Clock::currentDateTime()
28
return instance().currentDateTimeImpl();
31
uint Clock::currentSecondsSinceEpoch()
34
return instance().currentDateTimeImpl().toTime_t();
37
qint64 Clock::currentMilliSecondsSinceEpoch()
39
return instance().currentDateTimeImpl().toMSecsSinceEpoch();
42
QDateTime Clock::serialized(const QDateTime& dateTime)
44
auto time = dateTime.time();
45
if (time.isValid() && time.msec() != 0) {
46
return dateTime.addMSecs(-time.msec());
51
QDateTime Clock::datetimeUtc(int year, int month, int day, int hour, int min, int second)
53
return {QDate(year, month, day), QTime(hour, min, second), Qt::UTC};
56
QDateTime Clock::datetime(int year, int month, int day, int hour, int min, int second)
58
return {QDate(year, month, day), QTime(hour, min, second), Qt::LocalTime};
61
QDateTime Clock::datetimeUtc(qint64 msecSinceEpoch)
63
return QDateTime::fromMSecsSinceEpoch(msecSinceEpoch, Qt::UTC);
66
QDateTime Clock::datetime(qint64 msecSinceEpoch)
68
return QDateTime::fromMSecsSinceEpoch(msecSinceEpoch, Qt::LocalTime);
71
QDateTime Clock::parse(const QString& text, Qt::DateFormat format)
73
return QDateTime::fromString(text, format);
76
QDateTime Clock::parse(const QString& text, const QString& format)
78
return QDateTime::fromString(text, format);
81
Clock::~Clock() = default;
83
Clock::Clock() = default;
85
QDateTime Clock::currentDateTimeUtcImpl() const
87
return QDateTime::currentDateTimeUtc();
90
QDateTime Clock::currentDateTimeImpl() const
92
return QDateTime::currentDateTime();
95
void Clock::resetInstance()
100
void Clock::setInstance(Clock* clock)
102
m_instance = QSharedPointer<Clock>(clock);
105
const Clock& Clock::instance()
108
m_instance = QSharedPointer<Clock>(new Clock());