Skip to content

Commit

Permalink
Add DiffCurTime
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Jul 16, 2024
1 parent c8fb3e6 commit b7f1bc5
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 51 deletions.
2 changes: 1 addition & 1 deletion timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "plugininterface.h"

#define PLUGIN_NAME "Timestamp"
#define PLUGIN_VERSION "0.0.1"
#define PLUGIN_VERSION "0.0.2"
#define PLUGIN_WEBSITE "https://github.com/QuardCRT-platform/plugin-timestamp"

class Timestamp : public PluginInterface
Expand Down
27 changes: 17 additions & 10 deletions timestamp_en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ This is a plugin to convert timestamps.</source>
</message>
<message>
<location filename="timestampshowdialog.ui" line="26"/>
<location filename="timestampshowdialog.ui" line="168"/>
<location filename="timestampshowdialog.ui" line="229"/>
<source>Timestamp</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="40"/>
<location filename="timestampshowdialog.ui" line="134"/>
<location filename="timestampshowdialog.ui" line="175"/>
<location filename="timestampshowdialog.ui" line="202"/>
<location filename="timestampshowdialog.ui" line="109"/>
<location filename="timestampshowdialog.ui" line="167"/>
<location filename="timestampshowdialog.ui" line="181"/>
<source>Date</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="47"/>
<location filename="timestampshowdialog.ui" line="106"/>
<location filename="timestampshowdialog.ui" line="222"/>
<source>Millisecond timestamp</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="61"/>
<location filename="timestampshowdialog.ui" line="120"/>
<location filename="timestampshowdialog.ui" line="123"/>
<source>Microsecond timestamp</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="88"/>
<location filename="timestampshowdialog.ui" line="154"/>
<location filename="timestampshowdialog.ui" line="195"/>
<location filename="timestampshowdialog.ui" line="222"/>
<location filename="timestampshowdialog.ui" line="157"/>
<location filename="timestampshowdialog.ui" line="215"/>
<location filename="timestampshowdialog.ui" line="252"/>
<source>yyyy/M/d HH:mm:ss</source>
<translation></translation>
</message>
Expand All @@ -70,7 +70,14 @@ This is a plugin to convert timestamps.</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="244"/>
<location filename="timestampshowdialog.ui" line="137"/>
<location filename="timestampshowdialog.ui" line="174"/>
<location filename="timestampshowdialog.ui" line="188"/>
<source>Difference from current time</source>
<translation></translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="281"/>
<source>Close</source>
<translation></translation>
</message>
Expand Down
27 changes: 17 additions & 10 deletions timestamp_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ This is a plugin to convert timestamps.</source>
</message>
<message>
<location filename="timestampshowdialog.ui" line="26"/>
<location filename="timestampshowdialog.ui" line="168"/>
<location filename="timestampshowdialog.ui" line="229"/>
<source>Timestamp</source>
<translation>时间戳</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="40"/>
<location filename="timestampshowdialog.ui" line="134"/>
<location filename="timestampshowdialog.ui" line="175"/>
<location filename="timestampshowdialog.ui" line="202"/>
<location filename="timestampshowdialog.ui" line="109"/>
<location filename="timestampshowdialog.ui" line="167"/>
<location filename="timestampshowdialog.ui" line="181"/>
<source>Date</source>
<translation>日期</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="47"/>
<location filename="timestampshowdialog.ui" line="106"/>
<location filename="timestampshowdialog.ui" line="222"/>
<source>Millisecond timestamp</source>
<translation>毫秒时间戳</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="61"/>
<location filename="timestampshowdialog.ui" line="120"/>
<location filename="timestampshowdialog.ui" line="123"/>
<source>Microsecond timestamp</source>
<translation>微秒时间戳</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="88"/>
<location filename="timestampshowdialog.ui" line="154"/>
<location filename="timestampshowdialog.ui" line="195"/>
<location filename="timestampshowdialog.ui" line="222"/>
<location filename="timestampshowdialog.ui" line="157"/>
<location filename="timestampshowdialog.ui" line="215"/>
<location filename="timestampshowdialog.ui" line="252"/>
<source>yyyy/M/d HH:mm:ss</source>
<translation>yyyy/M/d HH:mm:ss</translation>
</message>
Expand All @@ -71,7 +71,14 @@ This is a plugin to convert timestamps.</source>
<translation>输入</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="244"/>
<location filename="timestampshowdialog.ui" line="137"/>
<location filename="timestampshowdialog.ui" line="174"/>
<location filename="timestampshowdialog.ui" line="188"/>
<source>Difference from current time</source>
<translation>与当前时间的相差</translation>
</message>
<message>
<location filename="timestampshowdialog.ui" line="281"/>
<source>Close</source>
<translation>关闭</translation>
</message>
Expand Down
42 changes: 30 additions & 12 deletions timestampshowdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ TimestampShowDialog::TimestampShowDialog(uint64_t timestamp, QWidget *parent)
ui->lineEditNowmts->setText(QString::number(dt.toMSecsSinceEpoch()));
ui->lineEditNowmmts->setText(QString::number(dt.toMSecsSinceEpoch()*1000));

uint64_t dts = 0;
uint64_t dtms = 0;
uint64_t dtmms = 0;
QDateTime maxDt(QDate(9999,12,31), QTime(23,59,59));
QDateTime inDt = QDateTime::fromSecsSinceEpoch(timestamp);
if(inDt.isValid() && inDt <= maxDt) {
ui->lineEditInts->setText(QString::number(timestamp));
ui->dateTimeEditIndt->setDateTime(inDt);
} else {
ui->lineEditInts->setText("0");
dts = timestamp;
}

QDateTime inmDt = QDateTime::fromMSecsSinceEpoch(timestamp);
if(inmDt.isValid() && inmDt <= maxDt) {
ui->lineEditInmts->setText(QString::number(timestamp));
ui->dateTimeEditInmdt->setDateTime(inmDt);
} else {
ui->lineEditInmts->setText("0");
dtms = timestamp;
}

QDateTime inmmDt = QDateTime::fromMSecsSinceEpoch(timestamp/1000);
if(inmmDt.isValid() && inmmDt <= maxDt) {
ui->lineEditInmmts->setText(QString::number(timestamp));
ui->dateTimeEditInmmdt->setDateTime(inmmDt);
} else {
ui->lineEditInmmts->setText("0");
dtmms = timestamp;
}

connect(ui->pushButtonClose, &QPushButton::clicked, this, [&](){
Expand All @@ -48,12 +48,30 @@ TimestampShowDialog::TimestampShowDialog(uint64_t timestamp, QWidget *parent)

m_timer = new QTimer(this);
m_timer->setInterval(1000);
connect(m_timer, &QTimer::timeout, [&](){
QDateTime dt = QDateTime::currentDateTime();
ui->dateTimeEditNow->setDateTime(dt);
ui->lineEditNowts->setText(QString::number(dt.toSecsSinceEpoch()));
ui->lineEditNowmts->setText(QString::number(dt.toMSecsSinceEpoch()));
ui->lineEditNowmmts->setText(QString::number(dt.toMSecsSinceEpoch()*1000));
connect(m_timer, &QTimer::timeout, [&,dts,dtms,dtmms](){
QDateTime cdt = QDateTime::currentDateTime();
uint64_t cdts = cdt.toSecsSinceEpoch();
uint64_t cdtms = cdt.toMSecsSinceEpoch();
uint64_t cdtmms = cdt.toMSecsSinceEpoch()*1000;
ui->dateTimeEditNow->setDateTime(cdt);
ui->lineEditNowts->setText(QString::number(cdts));
ui->lineEditNowmts->setText(QString::number(cdtms));
ui->lineEditNowmmts->setText(QString::number(cdtmms));
uint64_t diffdt = cdts>dts ? cdts-dts : dts-cdts;
uint64_t diffdtm = cdtms>dtms ? cdtms-dtms : dtms-cdtms;
uint64_t diffdtmm = cdtmms>dtmms ? cdtmms-dtmms : dtmms-cdtmms;
if(dts == 0 && dtms == 0 && dtmms == 0) {
ui->lineEditDiffCurTime->setText(QString::number(diffdt/(60ULL*60ULL*24ULL*365ULL)) + "y : " + QString::number(diffdt/(60ULL*60ULL*24ULL*30ULL)) + "m : " + QString::number(diffdt/(60ULL*60ULL*7ULL*30ULL)) + "w : " +QString::number(diffdt/(60ULL*60ULL*30ULL)) + "d : " + QString::number(diffdt/(60ULL*60ULL)) + "h : " + QString::number(diffdt/60ULL) + "m : " + QString::number(diffdt) + "s");
ui->lineEditDiffCurTimem->setText(QString::number(diffdtm/(60ULL*60ULL*24ULL*365ULL*1000ULL)) + "y : " + QString::number(diffdtm/(60ULL*60ULL*24ULL*30ULL*1000ULL)) + "m : " + QString::number(diffdtm/(60ULL*60ULL*7ULL*30ULL*1000ULL)) + "w : " +QString::number(diffdtm/(60ULL*60ULL*30ULL*1000ULL)) + "d : " + QString::number(diffdtm/(60ULL*60ULL*1000ULL)) + "h : " + QString::number(diffdtm/(60ULL*1000ULL)) + "m : " + QString::number(diffdtm/1000ULL) + "s");
ui->lineEditDiffCurTimemm->setText(QString::number(diffdtmm/(60ULL*60ULL*24ULL*365ULL*1000ULL*1000ULL)) + "y : " + QString::number(diffdtmm/(60ULL*60ULL*24ULL*30ULL*1000ULL*1000ULL)) + "m : " + QString::number(diffdtmm/(60ULL*60ULL*7ULL*30ULL*1000ULL*1000ULL)) + "w : " +QString::number(diffdtmm/(60ULL*60ULL*30ULL*1000ULL*1000ULL)) + "d : " + QString::number(diffdtmm/(60ULL*60ULL*1000ULL*1000ULL)) + "h : " + QString::number(diffdtmm/(60ULL*1000ULL*1000ULL)) + "m : " + QString::number(diffdtmm/1000ULL/1000ULL) + "s");
} else {
if(dts != 0)
ui->lineEditDiffCurTime->setText(QString::number(diffdt/(60ULL*60ULL*24ULL*365ULL)) + "y : " + QString::number(diffdt/(60ULL*60ULL*24ULL*30ULL)) + "m : " + QString::number(diffdt/(60ULL*60ULL*7ULL*30ULL)) + "w : " +QString::number(diffdt/(60ULL*60ULL*30ULL)) + "d : " + QString::number(diffdt/(60ULL*60ULL)) + "h : " + QString::number(diffdt/60ULL) + "m : " + QString::number(diffdt) + "s");
if(dtms != 0)
ui->lineEditDiffCurTimem->setText(QString::number(diffdtm/(60ULL*60ULL*24ULL*365ULL*1000ULL)) + "y : " + QString::number(diffdtm/(60ULL*60ULL*24ULL*30ULL*1000ULL)) + "m : " + QString::number(diffdtm/(60ULL*60ULL*7ULL*30ULL*1000ULL)) + "w : " +QString::number(diffdtm/(60ULL*60ULL*30ULL*1000ULL)) + "d : " + QString::number(diffdtm/(60ULL*60ULL*1000ULL)) + "h : " + QString::number(diffdtm/(60ULL*1000ULL)) + "m : " + QString::number(diffdtm/1000ULL) + "s");
if(dtmms != 0)
ui->lineEditDiffCurTimemm->setText(QString::number(diffdtmm/(60ULL*60ULL*24ULL*365ULL*1000ULL*1000ULL)) + "y : " + QString::number(diffdtmm/(60ULL*60ULL*24ULL*30ULL*1000ULL*1000ULL)) + "m : " + QString::number(diffdtmm/(60ULL*60ULL*7ULL*30ULL*1000ULL*1000ULL)) + "w : " +QString::number(diffdtmm/(60ULL*60ULL*30ULL*1000ULL*1000ULL)) + "d : " + QString::number(diffdtmm/(60ULL*60ULL*1000ULL*1000ULL)) + "h : " + QString::number(diffdtmm/(60ULL*1000ULL*1000ULL)) + "m : " + QString::number(diffdtmm/1000ULL/1000ULL) + "s");
}
});
m_timer->start();
}
Expand Down
92 changes: 74 additions & 18 deletions timestampshowdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
Expand All @@ -100,15 +107,22 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<item row="6" column="1" colspan="4">
<widget class="QLineEdit" name="lineEditDiffCurTimemm">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Millisecond timestamp</string>
<string>Date</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditInmts">
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditInts">
<property name="readOnly">
<bool>true</bool>
</property>
Expand All @@ -128,10 +142,10 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_12">
<item row="6" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Date</string>
<string>Difference from current time</string>
</property>
</widget>
</item>
Expand All @@ -155,27 +169,48 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditInts">
<item row="4" column="1" colspan="4">
<widget class="QLineEdit" name="lineEditDiffCurTime">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<item row="2" column="2">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Timestamp</string>
<string>Date</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_8">
<item row="5" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Difference from current time</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Date</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Difference from current time</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditInmts">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QDateTimeEdit" name="dateTimeEditIndt">
<property name="readOnly">
Expand All @@ -196,10 +231,24 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_10">
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Date</string>
<string>Millisecond timestamp</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Timestamp</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="4">
<widget class="QLineEdit" name="lineEditDiffCurTimem">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
Expand All @@ -223,6 +272,13 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="5">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit b7f1bc5

Please sign in to comment.