From 8cf7888fd57618e267e1cdff3231a170c9cfe052 Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Thu, 18 Jun 2009 09:18:13 +0200 Subject: [PATCH] * Wrong unit test and algorithm for leapyears (year 1900) --- src/Date.cpp | 12 +++++++++--- src/tests/date.t.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Date.cpp b/src/Date.cpp index 985c9643d..e72a7f767 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -303,9 +303,15 @@ bool Date::leapYear (int year) { bool ly = false; - if (!(year % 4)) ly = true; - else if (!(year % 400)) ly = true; - else if (!(year % 100)) ly = false; + if (!(year % 4)) + { + ly = true; + if (!(year % 100)) + { + ly = false; + if (!(year % 400)) ly =true; + } + } return ly; } diff --git a/src/tests/date.t.cpp b/src/tests/date.t.cpp index 1e8c597ae..113b5ca8b 100644 --- a/src/tests/date.t.cpp +++ b/src/tests/date.t.cpp @@ -82,7 +82,7 @@ int main (int argc, char** argv) t.ok (Date::leapYear (2008), "2008 is a leap year"); t.notok (Date::leapYear (2007), "2007 is not a leap year"); t.ok (Date::leapYear (2000), "2000 is a leap year"); - t.ok (Date::leapYear (1900), "1900 is a leap year"); + t.notok (Date::leapYear (1900), "1900 is not a leap year"); // Days in month. t.is (Date::daysInMonth (2, 2008), 29, "29 days in February 2008");