MCPcopy Create free account
hub / github.com/KDE/labplot / dateTimeDiffToString

Function dateTimeDiffToString

src/backend/worksheet/Worksheet.cpp:1107–1160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1105}
1106
1107QString dateTimeDiffToString(const QDateTime& dt0, const QDateTime& dt1) {
1108 // dt0 to dt1 is positive if dt0 is smaller than dt1
1109 QString result;
1110 qint64 diff;
1111 bool negative = false;
1112 ;
1113 if (dt0 < dt1)
1114 diff = dt0.msecsTo(dt1);
1115 else {
1116 diff = dt1.msecsTo(dt0);
1117 negative = true;
1118 }
1119 const qint64 dayToMsecs = 24 * 3600 * 1000;
1120 const qint64 hourToMsecs = 3600 * 1000;
1121 const qint64 minutesToMsecs = 60 * 1000;
1122
1123 qint64 days = diff / dayToMsecs;
1124 diff -= days * dayToMsecs;
1125 qint64 hours = diff / hourToMsecs;
1126 diff -= hours * hourToMsecs;
1127 qint64 minutes = diff / minutesToMsecs;
1128 diff -= minutes * minutesToMsecs;
1129 qint64 seconds = diff / 1000;
1130 diff -= seconds * 1000;
1131 qint64 msecs = diff;
1132
1133 if (negative)
1134 result += QStringLiteral("- ");
1135
1136 if (days > 0)
1137 result += QString::number(days) + QStringLiteral(" ") + QObject::tr("days") + QStringLiteral(" ");
1138
1139 if (hours > 0)
1140 result += QString::number(hours) + QStringLiteral(":");
1141 else
1142 result += QStringLiteral("00:");
1143
1144 if (minutes > 0)
1145 result += QString::number(minutes) + QStringLiteral(":");
1146 else
1147 result += QStringLiteral("00:");
1148
1149 if (seconds > 0)
1150 result += QString::number(seconds) + QStringLiteral(".");
1151 else
1152 result += QStringLiteral("00.");
1153
1154 if (msecs > 0)
1155 result += QString::number(msecs);
1156 else
1157 result += QStringLiteral("000");
1158
1159 return result;
1160}
1161
1162/*!
1163 * \brief Worksheet::cursorPosChanged

Callers 1

cursorPosChangedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected