1.1 --- a/XSLTools/XMLCalendar.py Mon Aug 29 18:28:06 2005 +0000
1.2 +++ b/XSLTools/XMLCalendar.py Tue Sep 06 22:23:34 2005 +0000
1.3 @@ -20,13 +20,39 @@
1.4 rows.append(row)
1.5 return rows
1.6
1.7 +# Helper functions.
1.8 +
1.9 +def get_previous_year_and_month(year, month):
1.10 + if month - 1 == 0:
1.11 + return year - 1, 12
1.12 + else:
1.13 + return year, month - 1
1.14 +
1.15 +def get_next_year_and_month(year, month):
1.16 + if month + 1 == 13:
1.17 + return year + 1, 1
1.18 + else:
1.19 + return year, month + 1
1.20 +
1.21 # XML production functions.
1.22
1.23 def write_month_to_document(doc, root, year, month):
1.24 weeks = monthcalendar(year, month)
1.25 month_element = root.appendChild(doc.createElement("month"))
1.26 +
1.27 + # Add navigational attributes.
1.28 +
1.29 month_element.setAttribute("number", str(month))
1.30 month_element.setAttribute("year", str(year))
1.31 + yp, mp = get_previous_year_and_month(year, month)
1.32 + month_element.setAttribute("number-previous", str(mp))
1.33 + month_element.setAttribute("year-previous", str(yp))
1.34 + yn, mn = get_next_year_and_month(year, month)
1.35 + month_element.setAttribute("number-next", str(mn))
1.36 + month_element.setAttribute("year-next", str(yn))
1.37 +
1.38 + # Add weeks and days.
1.39 +
1.40 for numbers in weeks:
1.41 week_element = month_element.appendChild(doc.createElement("week"))
1.42 for number in numbers: