Template:Calendar/doc

Usage notes

 * If no month is entered, the template will generate a calendar for the current month.
 * If no year is entered, the template will generate a calendar for the current year.
 * To remove the previous/next calendar links, set  as false
 * Number parameters are used to enter content into a date cell for the current month. Unlike the previous version of the template, these numbers are not associated with the date (e.g. the value entered for "01" is not necessarily associated with the first of the month). Rather, these numbers correspond to each 'square' of the calendar, where the upper leftmost square is designated "0". Single-digit numerals take a leading zero (e.g. 01, 02...).
 * Examples of usage are available in Category:Calendar templates.

Coding notes
The logic for the loop operation is as follows: Calculate the difference between calendar value x and the start date value (numeral associated with the day of the week the month starts on), and add 1. If the result of this expression is less than one, then the calendar value is part of the previous month. For these calendar values, take the number of days in the previous month and add to them the result of the following expression: calendar value x - the start date value + 1. If the result of the expression in the first sentence is 1 or greater then determine if calendar value x is equal to or greater than the sum of the number of days in the current month and the start date value. If so, then the calendar value is part of the following month. For these calendar values, subtract the sum of the number of days in the current month and the start date value from calendar value x and add 1. For all other values (the calendar values associated with the days of the current month), calculate the difference between calendar value x and the start date value and add 1.

The logic for the 5th & 6th week display is as follows: To determine whether or not the calendar should display a given week, find the sum of these variables: the number of days in the current month, the start date value, and six minus the end date value. Whether or not the week is displayed is dependent on whether this value exceeds 28 (for a fifth week), and then 35 (for a sixth week).