mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #478, allow to set timestamp by "setByYearMonthDayHourMinute"
This commit is contained in:
committed by
Mathew Sutcliffe
parent
85b7801bb9
commit
008792d95b
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
ITimestampBased::ITimestampBased()
|
||||
ITimestampBased::ITimestampBased() : m_timestampMSecsSinceEpoch(QDateTime::currentMSecsSinceEpoch())
|
||||
{ }
|
||||
|
||||
ITimestampBased::ITimestampBased(qint64 msSincePoch) : m_timestampMSecsSinceEpoch(msSincePoch)
|
||||
@@ -26,6 +26,39 @@ namespace BlackMisc
|
||||
return QDateTime::fromMSecsSinceEpoch(this->m_timestampMSecsSinceEpoch, Qt::UTC);
|
||||
}
|
||||
|
||||
void ITimestampBased::setByYearMonthDayHourMinute(const QString &yyyyMMddhhmmsszzz)
|
||||
{
|
||||
// yyyy MM dd hh mm ss zzz
|
||||
// 0123 45 67 89 01 23 456
|
||||
// 1234 56 78 90 12 34 567
|
||||
|
||||
QString s(yyyyMMddhhmmsszzz);
|
||||
s.remove(':').remove(' ').remove('-').remove('.'); // plain vanilla string
|
||||
int year(s.left(4).toInt());
|
||||
int month(s.mid(4, 2).toInt());
|
||||
int day(s.mid(6, 2).toInt());
|
||||
QDate date;
|
||||
date.setDate(year, month, day);
|
||||
QDateTime dt;
|
||||
dt.setOffsetFromUtc(0);
|
||||
dt.setDate(date);
|
||||
if (s.length() < 12)
|
||||
{
|
||||
this->setUtcTimestamp(dt);
|
||||
return;
|
||||
}
|
||||
|
||||
QTime t;
|
||||
int hour(s.mid(8, 2).toInt());
|
||||
int minute(s.mid(10, 2).toInt());
|
||||
int second(s.length() < 14 ? 0 : s.mid(12, 2).toInt());
|
||||
int ms(s.length() < 17 ? 0 : s.right(3).toInt());
|
||||
|
||||
t.setHMS(hour, minute, second, ms);
|
||||
dt.setTime(t);
|
||||
this->setUtcTimestamp(dt);
|
||||
}
|
||||
|
||||
void ITimestampBased::setUtcTimestamp(const QDateTime ×tamp)
|
||||
{
|
||||
this->m_timestampMSecsSinceEpoch = timestamp.toMSecsSinceEpoch();
|
||||
|
||||
@@ -44,6 +44,9 @@ namespace BlackMisc
|
||||
//! Timestamp as ms value
|
||||
void setMSecsSinceEpoch(qint64 mSecsSinceEpoch) { m_timestampMSecsSinceEpoch = mSecsSinceEpoch; }
|
||||
|
||||
//! Set by value such as "20141003231045"
|
||||
void setByYearMonthDayHourMinute(const QString &yyyyMMddhhmmss);
|
||||
|
||||
//! Set timestamp
|
||||
void setUtcTimestamp(const QDateTime ×tamp);
|
||||
|
||||
@@ -83,10 +86,10 @@ namespace BlackMisc
|
||||
//! As hh:mm
|
||||
QString getFormattedUtcTimestampHm() const;
|
||||
|
||||
//! As YYYY mm dd hh ss
|
||||
//! As yyyy MM dd HH mm ss
|
||||
QString getFormattedUtcTimestampYmdhms() const;
|
||||
|
||||
//! As YYYY mm dd hh ss.zzz
|
||||
//! As yyyy MM dd HH mm ss.zzz
|
||||
QString getFormattedUtcTimestampYmdhmsz() const;
|
||||
|
||||
//! Can given index be handled
|
||||
@@ -108,7 +111,7 @@ namespace BlackMisc
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
qint64 m_timestampMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); //!< timestamp value
|
||||
qint64 m_timestampMSecsSinceEpoch; //!< timestamp value
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user