diff --git a/AUTHORS b/AUTHORS index 39801e197..74e039659 100644 --- a/AUTHORS +++ b/AUTHORS @@ -108,4 +108,5 @@ suggestions: Yann Davin John Hammond Arkady Grudzinsky + Bernhard B diff --git a/ChangeLog b/ChangeLog index d70e965f4..9139776d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -122,6 +122,8 @@ (thanks to Michelle Crane). + Fixed bug #713, which fixes typos in the holidays-UK.rc file (thanks to Alexei Romanoff). + + Fixed bug #720, so that when the 'info' report renders total active time, + it uses a lossless format (thanks to Bernhard B). + Fixed bug #723, which displayed a misleading message when the output was truncated to a page. + Fixed bug #732, which fixes misleading messages and documentation for diff --git a/src/Duration.cpp b/src/Duration.cpp index fdd37d0c0..f83e881da 100644 --- a/src/Duration.cpp +++ b/src/Duration.cpp @@ -283,6 +283,22 @@ std::string Duration::formatCompact () const return std::string (formatted); } +//////////////////////////////////////////////////////////////////////////////// +std::string Duration::formatPrecise () const +{ + char formatted[24]; + + int days = mSecs / 86400; + int hours = (mSecs % 86400) / 3600; + int minutes = (mSecs % 3600) / 60; + int seconds = mSecs % 60; + + if (days > 0) sprintf (formatted, "%s%dd %d:%02d:%02d", (mNegative ? "-" : ""), days, hours, minutes, seconds); + else sprintf (formatted, "%s%d:%02d:%02d", (mNegative ? "-" : ""), hours, minutes, seconds); + + return std::string (formatted); +} + //////////////////////////////////////////////////////////////////////////////// bool Duration::operator< (const Duration& other) { diff --git a/src/Duration.h b/src/Duration.h index f4e57b6a2..318ef9370 100644 --- a/src/Duration.h +++ b/src/Duration.h @@ -55,6 +55,7 @@ public: std::string format () const; std::string formatCompact () const; + std::string formatPrecise () const; bool negative () const; static bool valid (const std::string&); diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index 19660eb72..04ddbc42c 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -386,7 +386,7 @@ int CmdInfo::execute (std::string& output) { row = journal.addRow (); journal.set (row, 0, STRING_CMD_INFO_TOTAL_ACTIVE); - journal.set (row, 1, Duration (total_time).format (), + journal.set (row, 1, Duration (total_time).formatPrecise (), (context.color () ? Color ("bold") : Color ())); } } diff --git a/test/duration.t.cpp b/test/duration.t.cpp index 83f1dc244..8574fd956 100644 --- a/test/duration.t.cpp +++ b/test/duration.t.cpp @@ -48,7 +48,7 @@ int convertDuration (const std::string& input) int main (int argc, char** argv) { - UnitTest t (631); + UnitTest t (651); Duration d; @@ -102,6 +102,28 @@ int main (int argc, char** argv) d = Duration (365 * 86400), t.is (d.formatCompact (), "1.0y", "365 days -> 1.0y"); d = Duration (365 * 86400 + 1), t.is (d.formatCompact (), "1.0y", "365 days + 1 sec -> 1.0y"); + // std::string formatPrecise (); + d = Duration (0), t.is (d.formatPrecise (), "0:00:00", "0 -> 0:00:00"); + d = Duration (1), t.is (d.formatPrecise (), "0:00:01", "1 -> 0:00:01"); + d = Duration (2), t.is (d.formatPrecise (), "0:00:02", "2 -> 0:00:02"); + d = Duration (59), t.is (d.formatPrecise (), "0:00:59", "59 -> 0:00:59"); + d = Duration (60), t.is (d.formatPrecise (), "0:01:00", "60 -> 0:01;00"); + d = Duration (119), t.is (d.formatPrecise (), "0:01:59", "119 -> 0:01:59"); + d = Duration (120), t.is (d.formatPrecise (), "0:02:00", "120 -> 0:02:00"); + d = Duration (121), t.is (d.formatPrecise (), "0:02:01", "121 -> 0:02:01"); + d = Duration (3599), t.is (d.formatPrecise (), "0:59:59", "3599 -> 0:59:59"); + d = Duration (3600), t.is (d.formatPrecise (), "1:00:00", "3600 -> 1:00:00"); + d = Duration (3601), t.is (d.formatPrecise (), "1:00:01", "3601 -> 1:00:01"); + d = Duration (86399), t.is (d.formatPrecise (), "23:59:59", "86399 -> 23:59:59"); + d = Duration (86400), t.is (d.formatPrecise (), "1d 0:00:00", "86400 -> 1d 0:00:00"); + d = Duration (86401), t.is (d.formatPrecise (), "1d 0:00:01", "86401 -> 1d 0:00:01"); + d = Duration (14 * 86400 - 1), t.is (d.formatPrecise (), "13d 23:59:59", "(14 * 86400) - 1 sec -> 13d 23:59:59"); + d = Duration (14 * 86400), t.is (d.formatPrecise (), "14d 0:00:00", "(14 * 86400) -> 14d 0:00:00"); + d = Duration (14 * 86400 + 1), t.is (d.formatPrecise (), "14d 0:00:01", "(14 * 86400) + 1 -> 14d 0:00:01"); + d = Duration (365 * 86400 - 1), t.is (d.formatPrecise (), "364d 23:59:59", "365 days - 1 sec -> 364d 23:59:59"); + d = Duration (365 * 86400), t.is (d.formatPrecise (), "365d 0:00:00", "365 days -> 365d 0:00:00"); + d = Duration (365 * 86400 + 1), t.is (d.formatPrecise (), "365d 0:00:01", "365 days + 1 sec -> 365d 0:00:01"); + // Iterate for a whole year. Why? Just to see where the boundaries are, // so that changes can be made with some reference point. d = Duration ( 1*86400), t.is (d.formatCompact (), "1d", "1*86400 -> 1d");