Created
September 4, 2015 18:58
-
-
Save junqueira/ca2076b494fc5ce1a24f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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