From f724943d404dcf73b4661d25332fff9e02443f0e Mon Sep 17 00:00:00 2001 From: Matthias Kupfer Date: Fri, 1 Aug 2008 17:43:53 +0000 Subject: [PATCH] - extended range for calendar view for years 1900-9999, each selectable year/month combination creates a correct month view - special case september 1752 partly prepared, but disabled as long as unneeded ;-) - enable via #define WITH_1752 svn path=/trunk/; revision=35016 --- reactos/dll/cpl/timedate/monthcal.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/reactos/dll/cpl/timedate/monthcal.c b/reactos/dll/cpl/timedate/monthcal.c index c764c120101..d07b13c810b 100644 --- a/reactos/dll/cpl/timedate/monthcal.c +++ b/reactos/dll/cpl/timedate/monthcal.c @@ -75,6 +75,19 @@ MonthCalNotifyControlParent(IN PMONTHCALWND infoPtr, return Ret; } +/* + * for the year range 1..9999 + * return 1 if is leap year otherwise 0 + */ +static WORD LeapYear(IN WORD Year) +{ + return +#ifdef WITH_1752 + (Year <= 1752) ? !(Year % 4) : +#endif + !(Year % 4) && ((Year % 100) || !(Year % 400)); +} + static WORD MonthCalMonthLength(IN WORD Month, IN WORD Year) @@ -82,9 +95,16 @@ MonthCalMonthLength(IN WORD Month, const BYTE MonthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0}; if(Month == 2) - return MonthDays[Month - 1] + ((Year % 400 == 0) ? 1 : ((Year % 100 != 0) && (Year % 4 == 0)) ? 1 : 0); + return MonthDays[Month - 1] + LeapYear(Year); else - return MonthDays[Month - 1]; + { +#ifdef WITH_1752 + if ((Year == 1752) && (Month == 9)) + return 19; // special case: September 1752 has no 3rd-13th + else +#endif + return MonthDays[Month - 1]; + } } static WORD @@ -134,7 +154,7 @@ MonthCalValidDate(IN WORD Day, if (Month < 1 || Month > 12 || Day == 0 || Day > MonthCalMonthLength(Month, Year) || - Year < 1980 || Year > 2099) + Year < 1899 || Year > 9999) { return FALSE; }