def METHOD_NAME(format, date):
	'''Method similar to strftime, but dealing with the weeknumber,
	day of the week and the year of that week.
	Week 1 is the first week where the Thursday is in the new year. So e.g. the
	last day of 2012 is a Monday. And therefore the calendar week for 31 Dec 2012
	is already week 1 2013.
	The locale decides whether a week starts on Monday (as the ISO standard would have
	it) or on Sunday. So depending on your locale Sun 6 Jan 2013 is either still week
	1 or already the first day of week 2.
	Codes supported by this method:
	  - C{%w} is replaced by the weekday as a decimal number [1,7], with 1 representing
	    either Monday or Sunday depending on the locale
	  - C{%W} is replaced by the weeknumber depending on the locale
	  - C{%Y} is replaced by the year with century as a decimal number, the year depends
	    on the weeknumber depending on the locale
	  - C{%%} is replaced by %
	Difference between this method and strftime is that:
	  1. It uses locale to determine the first day of the week
	  2. It returns the year that goes with the weeknumber
	'''
	# TODO: may want to add version of the codes that allow forcing
	#       Monday or Sunday as first day, e.g. using %u %U %X and %v %V %Z
	year, week, weekday = weekcalendar(date)
	def replacefunc(matchobj):
		code = matchobj.group(0)
		if code == '%w':
			return str(weekday)
		elif code == '%W':
			return '%02d' % week
		elif code == '%Y':
			return str(year)
		elif code == '%%':
			return '%'
		else:
			return code # ignore unsupported codes
	return re.sub(r'%.', replacefunc, format)