date.c
branchcustombridgeheads
changeset 5642 bfa6074e2833
parent 5249 b04b34842727
--- a/date.c	Tue Jan 02 18:40:37 2007 +0000
+++ b/date.c	Wed Jan 03 08:32:17 2007 +0000
@@ -6,9 +6,9 @@
 #include "variables.h"
 #include "macros.h"
 #include "vehicle.h"
-#include "network.h"
-#include "network_data.h"
-#include "network_server.h"
+#include "network/network.h"
+#include "network/network_data.h"
+#include "network/network_server.h"
 #include "functions.h"
 #include "currency.h"
 
@@ -92,9 +92,22 @@
 	int rem = date % (365 * 400 + 97);
 	uint16 x;
 
-	/* There are 24 leap years in 100 years */
-	yr += 100 * (rem / (365 * 100 + 24));
-	rem = rem % (365 * 100 + 24);
+	if (rem >= 365 * 100 + 25) {
+		/* There are 25 leap years in the first 100 years after
+		 * every 400th year, as every 400th year is a leap year */
+		yr  += 100;
+		rem -= 365 * 100 + 25;
+
+		/* There are 24 leap years in the next couple of 100 years */
+		yr += 100 * (rem / (365 * 100 + 24));
+		rem = (rem % (365 * 100 + 24));
+	}
+
+	if (!IsLeapYear(yr) && rem >= 365 * 4) {
+		/* The first 4 year of the century are not always a leap year */
+		yr  += 4;
+		rem -= 365 * 4;
+	}
 
 	/* There is 1 leap year every 4 years */
 	yr += 4 * (rem / (365 * 4 + 1));