--- /dev/null
+// monthviewgen.cpp - Xestia Calendar month view generation functions.
+//
+// (c) 2016 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
+
+#include "monthviewgen.h"
+
+using namespace std;
+
+int PreviousMonthNumberofDays(int Month, int Year){
+
+ // Work out what the previous month is.
+
+ // Return 31 if month matches.
+
+ if (Month == 1 || Month == 2 || Month == 4 ||
+ Month == 6 || Month == 8 || Month == 9 || Month == 11){
+
+ return 31;
+
+ }
+
+ // Return 30 if month matches.
+
+ if (Month == 5 || Month == 7 || Month == 10 || Month == 12){
+
+ return 30;
+
+ }
+
+ // Work out if year is a leap year and return 28 or 29
+ // for february.
+
+ if (Year % 4 == 0){
+
+ if (Year % 100 == 0){
+
+ if (Year % 400 == 0){
+
+ return 29;
+
+ } else {
+
+ return 28;
+
+ }
+
+ }
+
+ return 29;
+
+ } else {
+
+ return 28;
+
+ }
+
+}
+
--- /dev/null
+// monthviewgen.h - Xestia Calendar month view generation functions header.
+//
+// (c) 2016 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
+
+#ifndef __COMMON_MONTHVIEWGEN_H__
+#define __COMMON_MONTHVIEWGEN_H__
+
+#include <vector>
+#include <ctime>
+#include <iostream>
+
+int PreviousMonthNumberofDays(int Month, int Year);
+
+#endif
\ No newline at end of file
#include "../common/file.h"
#include "../common/text.h"
#include "../common/colour.h"
+#include "../common/monthviewgen.h"
TEST(CommonFunctions, FileTests){
ASSERT_EQ(ResultText4, OutputText4);
ASSERT_EQ(ResultText5, OutputText5);
+}
+
+TEST(CommonFunctions, PreviousMonthNumberofDays){
+
+ // Test the year 2015 (does not have a leap year).
+
+ ASSERT_EQ(30, PreviousMonthNumberofDays(12, 2015));
+
+ // Test the year 2016 (has a leap year).
+
+ ASSERT_EQ(31, PreviousMonthNumberofDays(1, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(2, 2016));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(4, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(5, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(6, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(7, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(8, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(9, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(10, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(11, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(12, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(1, 2017));
+
+ // Test the leap year section.
+
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2016));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2012));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2008));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2004));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2000));
+
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2015));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2014));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2013));
+
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2041));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2042));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2043));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2044));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2045));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2046));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2047));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2048));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2049));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2050));
+
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 1900));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2200));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2300));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2400));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2500));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2600));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2700));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2800));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 2900));
+ ASSERT_EQ(28, PreviousMonthNumberofDays(3, 3000));
+
+}
+
}
\ No newline at end of file