From ca933d7f39cdec4cdc24bcc599f1e754c2332953 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 20 Mar 2009 20:02:59 -0400 Subject: [PATCH] Unit Tests - duration - Corrected unit tests that were mistakenly using 'week' instead of 'weekly'. --- src/tests/duration.t.cpp | 2 +- src/util.cpp | 50 +++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/tests/duration.t.cpp b/src/tests/duration.t.cpp index a50b6a11d..77e46a95c 100644 --- a/src/tests/duration.t.cpp +++ b/src/tests/duration.t.cpp @@ -42,6 +42,7 @@ int main (int argc, char** argv) std::string d; d = "daily"; t.is (convertDuration (d), 1, "duration daily = 1"); + d = "weekdays"; t.is (convertDuration (d), 1, "duration weekdays = 1"); d = "day"; t.is (convertDuration (d), 1, "duration day = 1"); d = "0d"; t.is (convertDuration (d), 0, "duration 0d = 0"); d = "1d"; t.is (convertDuration (d), 1, "duration 1d = 1"); @@ -53,7 +54,6 @@ int main (int argc, char** argv) d = "sennight"; t.is (convertDuration (d), 7, "duration sennight = 7"); d = "biweekly"; t.is (convertDuration (d), 14, "duration biweekly = 14"); d = "fortnight"; t.is (convertDuration (d), 14, "duration fortnight = 14"); - d = "week"; t.is (convertDuration (d), 7, "duration week = 7"); d = "0w"; t.is (convertDuration (d), 0, "duration 0w = 0"); d = "1w"; t.is (convertDuration (d), 7, "duration 1w = 7"); d = "7w"; t.is (convertDuration (d), 49, "duration 7w = 49"); diff --git a/src/util.cpp b/src/util.cpp index 5c4ce9627..a506377af 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -95,19 +95,31 @@ void formatTimeDeltaDays (std::string& output, time_t delta) if (days > 365) sprintf (formatted, "%.1f yrs", (days / 365.2422)); else if (days > 84) - sprintf (formatted, "%1d mth%s", (int) (days / 30.6), ((int) (days / 30.6) == 1 ? "" : "s")); + sprintf (formatted, "%1d mth%s", + (int) (days / 30.6), + ((int) (days / 30.6) == 1 ? "" : "s")); else if (days > 13) - sprintf (formatted, "%d wk%s", (int) (days / 7.0), ((int) (days / 7.0) == 1 ? "" : "s")); + sprintf (formatted, "%d wk%s", + (int) (days / 7.0), + ((int) (days / 7.0) == 1 ? "" : "s")); else if (days > 5.0) - sprintf (formatted, "%d day%s", (int) days, ((int) days == 1 ? "" : "s")); + sprintf (formatted, "%d day%s", + (int) days, + ((int) days == 1 ? "" : "s")); else if (days > 1.0) sprintf (formatted, "%.1f days", days); else if (days * 24 > 1.0) - sprintf (formatted, "%d hr%s", (int) (days * 24.0), ((int) (days * 24.0) == 1 ? "" : "s")); + sprintf (formatted, "%d hr%s", + (int) (days * 24.0), + ((int) (days * 24.0) == 1 ? "" : "s")); else if (days * 24 * 60 > 1) - sprintf (formatted, "%d min%s", (int) (days * 24 * 60), ((int) (days * 24 * 60) == 1 ? "" : "s")); + sprintf (formatted, "%d min%s", + (int) (days * 24 * 60), + ((int) (days * 24 * 60) == 1 ? "" : "s")); else if (days * 24 * 60 * 60 > 1) - sprintf (formatted, "%d sec%s", (int) (days * 24 * 60 * 60), ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); + sprintf (formatted, "%d sec%s", + (int) (days * 24 * 60 * 60), + ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); else strcpy (formatted, "-"); @@ -123,19 +135,31 @@ std::string formatSeconds (time_t delta) if (days > 365) sprintf (formatted, "%.1f yrs", (days / 365.2422)); else if (days > 84) - sprintf (formatted, "%1d mth%s", (int) (days / 30.6), ((int) (days / 30.6) == 1 ? "" : "s")); + sprintf (formatted, "%1d mth%s", + (int) (days / 30.6), + ((int) (days / 30.6) == 1 ? "" : "s")); else if (days > 13) - sprintf (formatted, "%d wk%s", (int) (days / 7.0), ((int) (days / 7.0) == 1 ? "" : "s")); + sprintf (formatted, "%d wk%s", + (int) (days / 7.0), + ((int) (days / 7.0) == 1 ? "" : "s")); else if (days > 5.0) - sprintf (formatted, "%d day%s", (int) days, ((int) days == 1 ? "" : "s")); + sprintf (formatted, "%d day%s", + (int) days, + ((int) days == 1 ? "" : "s")); else if (days > 1.0) sprintf (formatted, "%.1f days", days); else if (days * 24 > 1.0) - sprintf (formatted, "%d hr%s", (int) (days * 24.0), ((int) (days * 24) == 1 ? "" : "s")); + sprintf (formatted, "%d hr%s", + (int) (days * 24.0), + ((int) (days * 24) == 1 ? "" : "s")); else if (days * 24 * 60 > 1) - sprintf (formatted, "%d min%s", (int) (days * 24 * 60), ((int) (days * 24 * 60) == 1 ? "" : "s")); + sprintf (formatted, "%d min%s", + (int) (days * 24 * 60), + ((int) (days * 24 * 60) == 1 ? "" : "s")); else if (days * 24 * 60 * 60 > 1) - sprintf (formatted, "%d sec%s", (int) (days * 24 * 60 * 60), ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); + sprintf (formatted, "%d sec%s", + (int) (days * 24 * 60 * 60), + ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); else strcpy (formatted, "-"); @@ -261,8 +285,8 @@ int convertDuration (const std::string& input) std::vector supported; supported.push_back ("daily"); supported.push_back ("day"); - supported.push_back ("weekdays"); supported.push_back ("weekly"); + supported.push_back ("weekdays"); supported.push_back ("sennight"); supported.push_back ("biweekly"); supported.push_back ("fortnight");