Skip to content

Instantly share code, notes, and snippets.

@junqueira
Created September 4, 2015 18:58
Show Gist options
  • Save junqueira/ca2076b494fc5ce1a24f to your computer and use it in GitHub Desktop.
Save junqueira/ca2076b494fc5ce1a24f to your computer and use it in GitHub Desktop.
import calendar
from datetime import datetime, date, timedelta
class Agenda(object):
def __init__(self):
self._month = datetime.today().month
self._year = datetime.today().year
def daysOfMonth(self, year=None, month=None):
"""
:param year:
:param month:
:return: days the month in parameters
"""
year = year or self._year
month = month or self._month
first_day_month = date(year, month, 1)
year, weekBase, dayBase = first_day_month.isocalendar()
sunday = 0
qtd_day_before = 0
if dayBase != sunday:
first_day_month = self.dif_date(-dayBase-1, first_day_month)
day = 0
list_of_days = []
for i in range(42):
day += 1
_date = self.dif_date(day, first_day_month)
list_of_days.append({
"day": _date
})
return list_of_days
def dif_date(self, day, date=None):
"""
:param day:
:param date:
:return: diferents day in date
"""
_date = date or self._day
day = _date.toordinal() + day
return date.fromordinal(day)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment