mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Bug Fix - broken unit tests on Ubuntu
- Fixed util.cpp formatSeconds and formatSecondsCompact, that were using an algorithm that accentuated rounding errors. - Fixed unit tests that were expecting wrong answers from the wrong algorithm above.
This commit is contained in:
parent
37411c7521
commit
eaeca45eae
2 changed files with 21 additions and 22 deletions
|
@ -62,7 +62,7 @@ int main (int argc, char** argv)
|
|||
t.is (formatSeconds (85 * 86400 - 1), "2 mths", "85 days - 1 sec -> 2 mths");
|
||||
t.is (formatSeconds (85 * 86400), "2 mths", "85 days -> 2 mths");
|
||||
t.is (formatSeconds (85 * 86400 + 1), "2 mths", "85 days + 1 sec -> 2 mths");
|
||||
t.is (formatSeconds (365 * 86400 - 1), "1.0 yrs", "365 days - 1 sec -> 1.0 yrs");
|
||||
t.is (formatSeconds (365 * 86400 - 1), "11 mths", "365 days - 1 sec -> 11 mths");
|
||||
t.is (formatSeconds (365 * 86400), "1.0 yrs", "365 days -> 1.0 yrs");
|
||||
t.is (formatSeconds (365 * 86400 + 1), "1.0 yrs", "365 days + 1 sec -> 1.0 yrs");
|
||||
|
||||
|
@ -87,7 +87,7 @@ int main (int argc, char** argv)
|
|||
t.is (formatSecondsCompact (85 * 86400 - 1), "2mo", "85 days - 1 sec -> 2mo");
|
||||
t.is (formatSecondsCompact (85 * 86400), "2mo", "85 days -> 2mo");
|
||||
t.is (formatSecondsCompact (85 * 86400 + 1), "2mo", "85 days + 1 sec -> 2mo");
|
||||
t.is (formatSecondsCompact (365 * 86400 - 1), "1.0y", "365 days - 1 sec -> 1.0y");
|
||||
t.is (formatSecondsCompact (365 * 86400 - 1), "11mo", "365 days - 1 sec -> 11mo");
|
||||
t.is (formatSecondsCompact (365 * 86400), "1.0y", "365 days -> 1.0y");
|
||||
t.is (formatSecondsCompact (365 * 86400 + 1), "1.0y", "365 days + 1 sec -> 1.0y");
|
||||
|
||||
|
|
39
src/util.cpp
39
src/util.cpp
|
@ -174,22 +174,22 @@ std::string formatSeconds (time_t delta)
|
|||
sprintf (formatted, "%d wk%s", // TODO i18n
|
||||
(int) (days / 7.0),
|
||||
((int) (days / 7.0) == 1 ? "" : "s")); // TODO i18n
|
||||
else if (days >= 1.0)
|
||||
else if (delta >= 86400)
|
||||
sprintf (formatted, "%d day%s", // TODO i18n
|
||||
(int) days,
|
||||
((int) days == 1 ? "" : "s")); // TODO i18n
|
||||
else if (days * 24 >= 1.0)
|
||||
else if (delta >= 3600)
|
||||
sprintf (formatted, "%d hr%s", // TODO i18n
|
||||
(int) (days * 24.0),
|
||||
((int) (days * 24) == 1 ? "" : "s")); // TODO i18n
|
||||
else if (days * 24 * 60 >= 1)
|
||||
(int) (delta / 3600),
|
||||
((int) (delta / 3600) == 1 ? "" : "s")); // TODO i18n
|
||||
else if (delta >= 60)
|
||||
sprintf (formatted, "%d min%s", // TODO i18n
|
||||
(int) (days * 24 * 60),
|
||||
((int) (days * 24 * 60) == 1 ? "" : "s")); // TODO i18n
|
||||
else if (days * 24 * 60 * 60 >= 1)
|
||||
(int) (delta / 60),
|
||||
((int) (delta / 60) == 1 ? "" : "s")); // TODO i18n
|
||||
else if (delta >= 1)
|
||||
sprintf (formatted, "%d sec%s", // TODO i18n
|
||||
(int) (days * 24 * 60 * 60),
|
||||
((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); // TODO i18n
|
||||
(int) delta,
|
||||
((int) delta == 1 ? "" : "s")); // TODO i18n
|
||||
else
|
||||
strcpy (formatted, "-"); // no i18n
|
||||
|
||||
|
@ -203,15 +203,14 @@ std::string formatSecondsCompact (time_t delta)
|
|||
char formatted[24];
|
||||
float days = (float) delta / 86400.0;
|
||||
|
||||
if (days >= 365) sprintf (formatted, "%.1fy", (days / 365.2422)); // TODO i18n
|
||||
else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); // TODO i18n
|
||||
else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); // TODO i18n
|
||||
else if (days >= 1.0) sprintf (formatted, "%dd", (int) days); // TODO i18n
|
||||
else if (days * 24 >= 1.0) sprintf (formatted, "%dh", (int) (days * 24.0)); // TODO i18n
|
||||
else if (days * 24 * 60 >= 1) sprintf (formatted, "%dm", (int) (days * 24 * 60)); // TODO i18n
|
||||
else if (days * 24 * 3600 >= 1) sprintf (formatted, "%ds", (int) (days * 24 * 60 * 60)); // TODO i18n
|
||||
else
|
||||
strcpy (formatted, "-"); // no i18n
|
||||
if (days >= 365) sprintf (formatted, "%.1fy", (days / 365.2422)); // TODO i18n
|
||||
else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); // TODO i18n
|
||||
else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); // TODO i18n
|
||||
else if (delta >= 86400) sprintf (formatted, "%dd", (int) days); // TODO i18n
|
||||
else if (delta >= 3600) sprintf (formatted, "%dh", (int) (delta / 3600)); // TODO i18n
|
||||
else if (delta >= 60) sprintf (formatted, "%dm", (int) (delta / 60)); // TODO i18n
|
||||
else if (delta >= 1) sprintf (formatted, "%ds", (int) delta); // TODO i18n
|
||||
else strcpy (formatted, "-");
|
||||
|
||||
return std::string (formatted);
|
||||
}
|
||||
|
@ -225,7 +224,7 @@ std::string formatBytes (size_t bytes)
|
|||
if (bytes >= 995000000) sprintf (formatted, "%.1f GiB", (bytes / 1000000000.0));
|
||||
else if (bytes >= 995000) sprintf (formatted, "%.1f MiB", (bytes / 1000000.0));
|
||||
else if (bytes >= 995) sprintf (formatted, "%.1f KiB", (bytes / 1000.0));
|
||||
else sprintf (formatted, "%d B", (int)bytes );
|
||||
else sprintf (formatted, "%d B", (int)bytes );
|
||||
|
||||
return commify (formatted);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue