Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>see <a href="http://www.nrf.com/modules.php?name=Documents&amp;op=viewlive&amp;sp_id=6019" rel="nofollow">http://www.nrf.com/modules.php?name=Documents&amp;op=viewlive&amp;sp_id=6019</a></p> <p>4-5-4 or 4-4-5 calendars are used to give consistent month lengths from year to year, so rather than reporting monthly sales from 1-31 January the month of January starts on say a sunday and ends Saturday. This way there is always a consistent number of weekends in a month and holidays don't move around, making monthly sales comparisoons from year to year feasible</p> <p>there is a lot of fiddling behind the scenes but 4-5-4 calendars are published - see link above.</p> <p>it sounds like you are trying to use them as a dimension for a star schema data warehouse? Are you looking for advice on implementing that? </p> <p>I really should have done some real work this evening</p> <pre><code>******************* Feb06 [[29, 30, 31, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25]] ******************* Mar06 [[26, 27, 28, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24, 25], [26, 27, 28, 29, 30, 31, 1]] ******************* Apr06 [[2, 3, 4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22], [23, 24, 25, 26, 27, 28, 29]] </code></pre> <p>the above seems correct eyeballing it against NRF calendars</p> <p>its from the below monstrosity, but it might help you do 15 years</p> <pre><code>import calendar calendar.setfirstweekday(calendar.SUNDAY) import datetime import pprint def addweek(yr): d = datetime.date(yr, 12, 31) if d.weekday() in (6,0,1): return True else: return False def printday(d): print d.day, if d.weekday() == 5: print def wksinthismth(cal): seq = [len(mth) for mth in cal] #print "seq", seq #special - but really need dates in cal if (len(seq) % 11 == 0 ) and len(seq) != 0 and addweek(2006): return 5 try: lenlastmth = seq[-1] except: #print "fail4" return 4 try: lenprevmth = seq[-2:-1][0] except: #print "fail5" return 5 try: lenprevprevmth = seq[-3:-2][0] except: lenprevprevmth = 4 if lenprevmth == []:return 5 if (lenlastmth == 4 and lenprevmth == 5 and lenprevprevmth == 5): #long january just passed return 5 #print lenlastmth, lenprevmth if (lenlastmth == 4 and lenprevmth == 4) : #print "ok5" return 5 else: #print "ok4" return 4 oneday = datetime.timedelta(days=1) startdate = datetime.date(2006,1,29) thisdate = startdate cal = [] thismth = [] thiswk = [] for i in range(800): thiswk.append(thisdate.day) if thisdate.weekday() == 5: #week over, decide how format it wks = wksinthismth(cal) if len(thismth) &lt;= wks-1: thismth.append(thiswk) else: cal.append(thismth) thismth = [] thismth.append(thiswk) thiswk = [] thisdate += oneday mthslist = ['Feb06', 'Mar06', 'Apr06', 'May06', 'Jun06', 'Jul06', 'Aug06', 'Sept06', 'Oct06', 'Nov06', 'Dec06', 'Jan07', 'Feb07', 'Mar07', 'Apr07', 'May07', 'Jun07', 'Jul07', 'Aug07', 'Sept07', 'Oct07', 'Nov07', 'Dec07', 'Jan08', 'Feb08', 'Mar08', 'Apr08', 'May08', 'Jun08', 'Jul08', 'Aug08', 'Sept08', 'Oct08', 'Nov08', 'Dec08', ] i = 0 for mth in cal: print "*******************", mthslist[i] pprint.pprint(mth) i += 1 # start week on Sun # if 31 dec is S M T then add week in Jan print [len(mth) for mth in cal] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload