KCoreAddons

kformatprivate.cpp
1 /*
2  This file is part of the KDE Frameworks
3 
4  SPDX-FileCopyrightText: 2013 Alex Merry <[email protected]>
5  SPDX-FileCopyrightText: 2013 John Layt <[email protected]>
6  SPDX-FileCopyrightText: 2010 Michael Leupold <[email protected]>
7  SPDX-FileCopyrightText: 2009 Michael Pyne <[email protected]>
8  SPDX-FileCopyrightText: 2008 Albert Astals Cid <[email protected]>
9 
10  SPDX-License-Identifier: LGPL-2.0-or-later
11 */
12 
13 #include "kformatprivate_p.h"
14 
15 #include <QDateTime>
16 
17 #include <math.h>
18 
19 KFormatPrivate::KFormatPrivate(const QLocale &locale)
20 {
21  m_locale = locale;
22 }
23 
24 KFormatPrivate::~KFormatPrivate()
25 {
26 }
27 
28 constexpr double bpow(int exp)
29 {
30  return (exp > 0) ? 2.0 * bpow(exp - 1) : (exp < 0) ? 0.5 * bpow(exp + 1) : 1.0;
31 }
32 
33 QString KFormatPrivate::formatValue(double value,
34  KFormat::Unit unit,
35  QString unitString,
36  int precision,
37  KFormat::UnitPrefix prefix,
38  KFormat::BinaryUnitDialect dialect) const
39 {
40  if (dialect <= KFormat::DefaultBinaryDialect || dialect > KFormat::LastBinaryDialect) {
41  dialect = KFormat::IECBinaryDialect;
42  }
43 
44  if (static_cast<int>(prefix) < static_cast<int>(KFormat::UnitPrefix::Yocto) || static_cast<int>(prefix) > static_cast<int>(KFormat::UnitPrefix::Yotta)) {
46  }
47 
48  double multiplier = 1024.0;
49  if (dialect == KFormat::MetricBinaryDialect) {
50  multiplier = 1000.0;
51  }
52 
53  int power = 0;
54  if (prefix == KFormat::UnitPrefix::AutoAdjust) {
55  double adjustValue = qAbs(value);
56  while (adjustValue >= multiplier) {
57  adjustValue /= multiplier;
58  power += 1;
59  }
60  while (adjustValue && adjustValue < 1.0) {
61  adjustValue *= multiplier;
62  power -= 1;
63  }
64  const KFormat::UnitPrefix map[] = {
82  };
83  power = std::max(-8, std::min(8, power));
84  prefix = map[power + 8];
85  }
86 
87  if (prefix == KFormat::UnitPrefix::Unity && unit == KFormat::Unit::Byte) {
88  precision = 0;
89  }
90 
91  struct PrefixMapEntry {
92  KFormat::UnitPrefix prefix;
93  double decimalFactor;
94  double binaryFactor;
95  QString prefixCharSI;
96  QString prefixCharIEC;
97  };
98 
99  const PrefixMapEntry map[] = {
100  {KFormat::UnitPrefix::Yocto, 1e-24, bpow(-80), tr("y", "SI prefix for 10^⁻24"), QString()},
101  {KFormat::UnitPrefix::Zepto, 1e-21, bpow(-70), tr("z", "SI prefix for 10^⁻21"), QString()},
102  {KFormat::UnitPrefix::Atto, 1e-18, bpow(-60), tr("a", "SI prefix for 10^⁻18"), QString()},
103  {KFormat::UnitPrefix::Femto, 1e-15, bpow(-50), tr("f", "SI prefix for 10^⁻15"), QString()},
104  {KFormat::UnitPrefix::Pico, 1e-12, bpow(-40), tr("p", "SI prefix for 10^⁻12"), QString()},
105  {KFormat::UnitPrefix::Nano, 1e-9, bpow(-30), tr("n", "SI prefix for 10^⁻9"), QString()},
106  {KFormat::UnitPrefix::Micro, 1e-6, bpow(-20), tr("µ", "SI prefix for 10^⁻6"), QString()},
107  {KFormat::UnitPrefix::Milli, 1e-3, bpow(-10), tr("m", "SI prefix for 10^⁻3"), QString()},
108  {KFormat::UnitPrefix::Unity, 1.0, 1.0, QString(), QString()},
109  {KFormat::UnitPrefix::Kilo, 1e3, bpow(10), tr("k", "SI prefix for 10^3"), tr("Ki", "IEC binary prefix for 2^10")},
110  {KFormat::UnitPrefix::Mega, 1e6, bpow(20), tr("M", "SI prefix for 10^6"), tr("Mi", "IEC binary prefix for 2^20")},
111  {KFormat::UnitPrefix::Giga, 1e9, bpow(30), tr("G", "SI prefix for 10^9"), tr("Gi", "IEC binary prefix for 2^30")},
112  {KFormat::UnitPrefix::Tera, 1e12, bpow(40), tr("T", "SI prefix for 10^12"), tr("Ti", "IEC binary prefix for 2^40")},
113  {KFormat::UnitPrefix::Peta, 1e15, bpow(50), tr("P", "SI prefix for 10^15"), tr("Pi", "IEC binary prefix for 2^50")},
114  {KFormat::UnitPrefix::Exa, 1e18, bpow(60), tr("E", "SI prefix for 10^18"), tr("Ei", "IEC binary prefix for 2^60")},
115  {KFormat::UnitPrefix::Zetta, 1e21, bpow(70), tr("Z", "SI prefix for 10^21"), tr("Zi", "IEC binary prefix for 2^70")},
116  {KFormat::UnitPrefix::Yotta, 1e24, bpow(80), tr("Y", "SI prefix for 10^24"), tr("Yi", "IEC binary prefix for 2^80")},
117  };
118 
119  auto entry = std::find_if(std::begin(map), std::end(map), [prefix](const PrefixMapEntry &e) {
120  return e.prefix == prefix;
121  });
122 
123  switch (unit) {
124  case KFormat::Unit::Bit:
125  unitString = tr("bit", "Symbol of binary digit");
126  break;
127  case KFormat::Unit::Byte:
128  unitString = tr("B", "Symbol of byte");
129  break;
131  unitString = tr("m", "Symbol of meter");
132  break;
134  unitString = tr("Hz", "Symbol of hertz");
135  break;
136  case KFormat::Unit::Other:
137  break;
138  }
139 
140  if (prefix == KFormat::UnitPrefix::Unity) {
141  QString numString = m_locale.toString(value, 'f', precision);
142  //: value without prefix, format "<val> <unit>"
143  return tr("%1 %2", "no Prefix").arg(numString, unitString);
144  }
145 
146  QString prefixString;
147  if (dialect == KFormat::MetricBinaryDialect) {
148  value /= entry->decimalFactor;
149  prefixString = entry->prefixCharSI;
150  } else {
151  value /= entry->binaryFactor;
152  if (dialect == KFormat::IECBinaryDialect) {
153  prefixString = entry->prefixCharIEC;
154  } else {
155  prefixString = entry->prefixCharSI.toUpper();
156  }
157  }
158 
159  QString numString = m_locale.toString(value, 'f', precision);
160 
161  //: value with prefix, format "<val> <prefix><unit>"
162  return tr("%1 %2%3", "MetricBinaryDialect").arg(numString, prefixString, unitString);
163 }
164 
165 QString KFormatPrivate::formatByteSize(double size, int precision, KFormat::BinaryUnitDialect dialect, KFormat::BinarySizeUnits units) const
166 {
167  // Current KDE default is IECBinaryDialect
168  if (dialect <= KFormat::DefaultBinaryDialect || dialect > KFormat::LastBinaryDialect) {
169  dialect = KFormat::IECBinaryDialect;
170  }
171 
172  // Current KDE default is to auto-adjust so the size falls in the range 0 to 1000/1024
173  if (units < KFormat::DefaultBinaryUnits || units > KFormat::UnitLastUnit) {
175  }
176 
177  int unit = 0; // Selects what unit to use
178  double multiplier = 1024.0;
179 
180  if (dialect == KFormat::MetricBinaryDialect) {
181  multiplier = 1000.0;
182  }
183 
184  // If a specific unit conversion is given, use it directly. Otherwise
185  // search until the result is in [0, multiplier] (or out of our range).
186  if (units == KFormat::DefaultBinaryUnits) {
187  while (qAbs(size) >= multiplier && unit < int(KFormat::UnitYottaByte)) {
188  size /= multiplier;
189  ++unit;
190  }
191  } else {
192  // A specific unit is in use
193  unit = static_cast<int>(units);
194  if (unit > 0) {
195  size /= pow(multiplier, unit);
196  }
197  }
198 
199  // Bytes, no rounding
200  if (unit == 0) {
201  precision = 0;
202  }
203 
204  QString numString = m_locale.toString(size, 'f', precision);
205 
206  // Do not remove "//:" comments below, they are used by the translators.
207  // NB: we cannot pass pluralization arguments, as the size may be negative
208  if (dialect == KFormat::MetricBinaryDialect) {
209  switch (unit) {
210  case KFormat::UnitByte:
211  //: MetricBinaryDialect size in bytes
212  return tr("%1 B", "MetricBinaryDialect").arg(numString);
214  //: MetricBinaryDialect size in 1000 bytes
215  return tr("%1 kB", "MetricBinaryDialect").arg(numString);
217  //: MetricBinaryDialect size in 10^6 bytes
218  return tr("%1 MB", "MetricBinaryDialect").arg(numString);
220  //: MetricBinaryDialect size in 10^9 bytes
221  return tr("%1 GB", "MetricBinaryDialect").arg(numString);
223  //: MetricBinaryDialect size in 10^12 bytes
224  return tr("%1 TB", "MetricBinaryDialect").arg(numString);
226  //: MetricBinaryDialect size in 10^15 bytes
227  return tr("%1 PB", "MetricBinaryDialect").arg(numString);
229  //: MetricBinaryDialect size in 10^18 byte
230  return tr("%1 EB", "MetricBinaryDialect").arg(numString);
232  //: MetricBinaryDialect size in 10^21 bytes
233  return tr("%1 ZB", "MetricBinaryDialect").arg(numString);
235  //: MetricBinaryDialect size in 10^24 bytes
236  return tr("%1 YB", "MetricBinaryDialect").arg(numString);
237  }
238  } else if (dialect == KFormat::JEDECBinaryDialect) {
239  switch (unit) {
240  case KFormat::UnitByte:
241  //: JEDECBinaryDialect memory size in bytes
242  return tr("%1 B", "JEDECBinaryDialect").arg(numString);
244  //: JEDECBinaryDialect memory size in 1024 bytes
245  return tr("%1 KB", "JEDECBinaryDialect").arg(numString);
247  //: JEDECBinaryDialect memory size in 10^20 bytes
248  return tr("%1 MB", "JEDECBinaryDialect").arg(numString);
250  //: JEDECBinaryDialect memory size in 10^30 bytes
251  return tr("%1 GB", "JEDECBinaryDialect").arg(numString);
253  //: JEDECBinaryDialect memory size in 10^40 bytes
254  return tr("%1 TB", "JEDECBinaryDialect").arg(numString);
256  //: JEDECBinaryDialect memory size in 10^50 bytes
257  return tr("%1 PB", "JEDECBinaryDialect").arg(numString);
259  //: JEDECBinaryDialect memory size in 10^60 bytes
260  return tr("%1 EB", "JEDECBinaryDialect").arg(numString);
262  //: JEDECBinaryDialect memory size in 10^70 bytes
263  return tr("%1 ZB", "JEDECBinaryDialect").arg(numString);
265  //: JEDECBinaryDialect memory size in 10^80 bytes
266  return tr("%1 YB", "JEDECBinaryDialect").arg(numString);
267  }
268  } else { // KFormat::IECBinaryDialect, KFormat::DefaultBinaryDialect
269  switch (unit) {
270  case KFormat::UnitByte:
271  //: IECBinaryDialect size in bytes
272  return tr("%1 B", "IECBinaryDialect").arg(numString);
274  //: IECBinaryDialect size in 1024 bytes
275  return tr("%1 KiB", "IECBinaryDialect").arg(numString);
277  //: IECBinaryDialect size in 10^20 bytes
278  return tr("%1 MiB", "IECBinaryDialect").arg(numString);
280  //: IECBinaryDialect size in 10^30 bytes
281  return tr("%1 GiB", "IECBinaryDialect").arg(numString);
283  //: IECBinaryDialect size in 10^40 bytes
284  return tr("%1 TiB", "IECBinaryDialect").arg(numString);
286  //: IECBinaryDialect size in 10^50 bytes
287  return tr("%1 PiB", "IECBinaryDialect").arg(numString);
289  //: IECBinaryDialect size in 10^60 bytes
290  return tr("%1 EiB", "IECBinaryDialect").arg(numString);
292  //: IECBinaryDialect size in 10^70 bytes
293  return tr("%1 ZiB", "IECBinaryDialect").arg(numString);
295  //: IECBinaryDialect size in 10^80 bytes
296  return tr("%1 YiB", "IECBinaryDialect").arg(numString);
297  }
298  }
299 
300  // Should never reach here
301  Q_ASSERT(false);
302  return numString;
303 }
304 
305 enum TimeConstants {
306  MSecsInDay = 86400000,
307  MSecsInHour = 3600000,
308  MSecsInMinute = 60000,
309  MSecsInSecond = 1000,
310 };
311 
312 QString KFormatPrivate::formatDuration(quint64 msecs, KFormat::DurationFormatOptions options) const
313 {
314  quint64 ms = msecs;
315  if (options & KFormat::HideSeconds) {
316  // round to nearest minute
317  ms = qRound64(ms / (qreal)MSecsInMinute) * MSecsInMinute;
318  } else if (!(options & KFormat::ShowMilliseconds)) {
319  // round to nearest second
320  ms = qRound64(ms / (qreal)MSecsInSecond) * MSecsInSecond;
321  }
322 
323  int hours = ms / MSecsInHour;
324  ms = ms % MSecsInHour;
325  int minutes = ms / MSecsInMinute;
326  ms = ms % MSecsInMinute;
327  int seconds = ms / MSecsInSecond;
328  ms = ms % MSecsInSecond;
329 
330  if ((options & KFormat::InitialDuration) == KFormat::InitialDuration) {
331  if ((options & KFormat::FoldHours) == KFormat::FoldHours && (options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
332  //: @item:intext Duration format minutes, seconds and milliseconds
333  return tr("%1m%2.%3s").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')).arg(ms, 3, 10, QLatin1Char('0'));
334  } else if ((options & KFormat::FoldHours) == KFormat::FoldHours) {
335  //: @item:intext Duration format minutes and seconds
336  return tr("%1m%2s").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'));
337  } else if ((options & KFormat::HideSeconds) == KFormat::HideSeconds) {
338  //: @item:intext Duration format hours and minutes
339  return tr("%1h%2m").arg(hours, 1, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0'));
340  } else if ((options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
341  //: @item:intext Duration format hours, minutes, seconds, milliseconds
342  return tr("%1h%2m%3.%4s")
343  .arg(hours, 1, 10, QLatin1Char('0'))
344  .arg(minutes, 2, 10, QLatin1Char('0'))
345  .arg(seconds, 2, 10, QLatin1Char('0'))
346  .arg(ms, 3, 10, QLatin1Char('0'));
347  } else { // Default
348  //: @item:intext Duration format hours, minutes, seconds
349  return tr("%1h%2m%3s").arg(hours, 1, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'));
350  }
351 
352  } else {
353  if ((options & KFormat::FoldHours) == KFormat::FoldHours && (options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
354  //: @item:intext Duration format minutes, seconds and milliseconds
355  return tr("%1:%2.%3").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')).arg(ms, 3, 10, QLatin1Char('0'));
356  } else if ((options & KFormat::FoldHours) == KFormat::FoldHours) {
357  //: @item:intext Duration format minutes and seconds
358  return tr("%1:%2").arg(hours * 60 + minutes, 1, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'));
359  } else if ((options & KFormat::HideSeconds) == KFormat::HideSeconds) {
360  //: @item:intext Duration format hours and minutes
361  return tr("%1:%2").arg(hours, 1, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0'));
362  } else if ((options & KFormat::ShowMilliseconds) == KFormat::ShowMilliseconds) {
363  //: @item:intext Duration format hours, minutes, seconds, milliseconds
364  return tr("%1:%2:%3.%4")
365  .arg(hours, 1, 10, QLatin1Char('0'))
366  .arg(minutes, 2, 10, QLatin1Char('0'))
367  .arg(seconds, 2, 10, QLatin1Char('0'))
368  .arg(ms, 3, 10, QLatin1Char('0'));
369  } else { // Default
370  //: @item:intext Duration format hours, minutes, seconds
371  return tr("%1:%2:%3").arg(hours, 1, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'));
372  }
373  }
374 
375  Q_UNREACHABLE();
376  return QString();
377 }
378 
379 QString KFormatPrivate::formatDecimalDuration(quint64 msecs, int decimalPlaces) const
380 {
381  if (msecs >= MSecsInDay) {
382  //: @item:intext %1 is a real number, e.g. 1.23 days
383  return tr("%1 days").arg(m_locale.toString(msecs / (MSecsInDay * 1.0), 'f', decimalPlaces));
384  } else if (msecs >= MSecsInHour) {
385  //: @item:intext %1 is a real number, e.g. 1.23 hours
386  return tr("%1 hours").arg(m_locale.toString(msecs / (MSecsInHour * 1.0), 'f', decimalPlaces));
387  } else if (msecs >= MSecsInMinute) {
388  //: @item:intext %1 is a real number, e.g. 1.23 minutes
389  return tr("%1 minutes").arg(m_locale.toString(msecs / (MSecsInMinute * 1.0), 'f', decimalPlaces));
390  } else if (msecs >= MSecsInSecond) {
391  //: @item:intext %1 is a real number, e.g. 1.23 seconds
392  return tr("%1 seconds").arg(m_locale.toString(msecs / (MSecsInSecond * 1.0), 'f', decimalPlaces));
393  }
394  //: @item:intext %1 is a whole number
395  //~ singular %n millisecond
396  //~ plural %n milliseconds
397  return tr("%n millisecond(s)", nullptr, msecs);
398 }
399 
400 enum DurationUnits {
401  Days = 0,
402  Hours,
403  Minutes,
404  Seconds,
405 };
406 
407 static QString formatSingleDuration(DurationUnits units, int n)
408 {
409  // NB: n is guaranteed to be non-negative
410  switch (units) {
411  case Days:
412  //: @item:intext %n is a whole number
413  //~ singular %n day
414  //~ plural %n days
415  return KFormatPrivate::tr("%n day(s)", nullptr, n);
416  case Hours:
417  //: @item:intext %n is a whole number
418  //~ singular %n hour
419  //~ plural %n hours
420  return KFormatPrivate::tr("%n hour(s)", nullptr, n);
421  case Minutes:
422  //: @item:intext %n is a whole number
423  //~ singular %n minute
424  //~ plural %n minutes
425  return KFormatPrivate::tr("%n minute(s)", nullptr, n);
426  case Seconds:
427  //: @item:intext %n is a whole number
428  //~ singular %n second
429  //~ plural %n seconds
430  return KFormatPrivate::tr("%n second(s)", nullptr, n);
431  }
432  Q_ASSERT(false);
433  return QString();
434 }
435 
436 QString KFormatPrivate::formatSpelloutDuration(quint64 msecs) const
437 {
438  quint64 ms = msecs;
439  int days = ms / MSecsInDay;
440  ms = ms % (MSecsInDay);
441  int hours = ms / MSecsInHour;
442  ms = ms % MSecsInHour;
443  int minutes = ms / MSecsInMinute;
444  ms = ms % MSecsInMinute;
445  int seconds = qRound(ms / 1000.0);
446 
447  // Handle correctly problematic case #1 (look at KFormatTest::prettyFormatDuration())
448  if (seconds == 60) {
449  return formatSpelloutDuration(msecs - ms + MSecsInMinute);
450  }
451 
452  if (days && hours) {
453  /*: @item:intext days and hours. This uses the previous item:intext messages.
454  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
455  return tr("%1 and %2").arg(formatSingleDuration(Days, days), formatSingleDuration(Hours, hours));
456  } else if (days) {
457  return formatSingleDuration(Days, days);
458  } else if (hours && minutes) {
459  /*: @item:intext hours and minutes. This uses the previous item:intext messages.
460  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
461  return tr("%1 and %2").arg(formatSingleDuration(Hours, hours), formatSingleDuration(Minutes, minutes));
462  } else if (hours) {
463  return formatSingleDuration(Hours, hours);
464  } else if (minutes && seconds) {
465  /*: @item:intext minutes and seconds. This uses the previous item:intext messages.
466  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
467  return tr("%1 and %2").arg(formatSingleDuration(Minutes, minutes), formatSingleDuration(Seconds, seconds));
468  } else if (minutes) {
469  return formatSingleDuration(Minutes, minutes);
470  } else {
471  return formatSingleDuration(Seconds, seconds);
472  }
473 }
474 
475 QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const
476 {
477  if (!date.isValid()) {
478  return tr("Invalid date", "used when a relative date string can't be generated because the date is invalid");
479  }
480 
481  const qint64 daysTo = QDate::currentDate().daysTo(date);
482  if (daysTo > 2 || daysTo < -2) {
483  return m_locale.toString(date, format);
484  }
485 
486  switch (daysTo) {
487  case 2:
488  return tr("In two days");
489  case 1:
490  return tr("Tomorrow");
491  case 0:
492  return tr("Today");
493  case -1:
494  return tr("Yesterday");
495  case -2:
496  return tr("Two days ago");
497  }
498  Q_UNREACHABLE();
499 }
500 
501 QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const
502 {
504  const qint64 daysTo = dateTime.daysTo(now);
505  if (daysTo > 2 || daysTo < -2) {
506  return m_locale.toString(dateTime, format);
507  }
508 
509  const auto secsToNow = dateTime.secsTo(now);
510  if (secsToNow >= 0 && secsToNow < 60 * 60) {
511  const int minutesToNow = secsToNow / 60;
512  if (minutesToNow <= 1) {
513  return tr("Just now");
514  } else {
515  return tr("%1 minutes ago").arg(minutesToNow);
516  }
517  }
518 
519  /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time
520  If this does not fit the grammar of your language please contact the i18n team to solve the problem */
521  return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format), m_locale.toString(dateTime.time(), format));
522 }
Yi/Y/Y 2^80/10^24.
PiB/PB/PB 2^50/10^15 bytes.
Definition: kformat.h:94
qint64 daysTo(const QDate &d) const const
KiB, MiB, etc. 2^(10*n)
Definition: kformat.h:173
QString toUpper() const const
GiB/GB/GB 2^30/10^09 bytes.
Definition: kformat.h:92
UnitPrefix
These prefixes are used in KDE by the formatValue() function.
Definition: kformat.h:126
BinarySizeUnits
These binary units are used in KDE by the formatByteSize() function.
Definition: kformat.h:84
Mi/M/M 2^20/10^06.
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
qint64 daysTo(const QDateTime &other) const const
KiB/KB/kB 1024/1000 bytes.
Definition: kformat.h:90
QTime time() const const
Ei/E/E 2^60/10^18.
Pi/P/P 2^50/10^15.
Fold the hours into the minutes, e.g. 83:45 or 83m45s, overrides HideSeconds.
Definition: kformat.h:188
Zi/Z/Z 2^70/10^21.
Hide the seconds, e.g. 1:23 or 1h23m, overrides ShowMilliseconds.
Definition: kformat.h:187
MiB/MB/MB 2^20/10^06 bytes.
Definition: kformat.h:91
Ki/K/k 1024/1000.
bool isValid() const const
KB, MB, etc. 2^(10*n)
Definition: kformat.h:174
YiB/YB/YB 2^80/10^24 bytes.
Definition: kformat.h:97
Ti/T/T 2^40/10^12.
EiB/EB/EB 2^60/10^18 bytes.
Definition: kformat.h:95
ZiB/ZB/ZB 2^70/10^21 bytes.
Definition: kformat.h:96
Unit
These units are used in KDE by the formatValue() function.
Definition: kformat.h:107
QDateTime currentDateTime()
QDate date() const const
qint64 secsTo(const QDateTime &other) const const
BinaryUnitDialect
This enum chooses what dialect is used for binary units.
Definition: kformat.h:171
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QDate currentDate()
Default formatting in localized 1h23m45s format.
Definition: kformat.h:185
Gi/G/G 2^30/10^09.
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
Definition: kformat.h:86
TiB/TB/TB 2^40/10^12 bytes.
Definition: kformat.h:93
QFuture< void > map(Sequence &sequence, MapFunctor function)
SI Units, kB, MB, etc. 10^(3*n)
Definition: kformat.h:175
B 1 byte.
Definition: kformat.h:89
Include milliseconds in format, e.g. 1:23:45.678.
Definition: kformat.h:186
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 18 2021 23:02:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.