/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def quarters_range(date_to, date_from=None): result = [] if date_from is None: date_from = datetime.now() quarter_from = (date_from.month/4)+1 quarter_to = (date_to.month/4)+1 for year in range(date_from.year, date_to.year+1): for quarter in range(1, 5): if date_to.year == year and quarter >= quarter_to: break if date_from.year == year and quarter <= quarter_from: continue result.append([quarter, year]) return result