Created
February 26, 2014 02:27
-
-
Save romulojales/9222361 to your computer and use it in GitHub Desktop.
Some functional methods with months
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 | |
import pytz | |
def month_range(year, month): | |
init = datetime(year, month, 1, 0, 0, 0, 0, tzinfo=pytz.UTC) | |
max_day_month = calendar.monthrange(year, month)[1] | |
final = datetime(year, month, max_day_month, datetime.max.hour, datetime.max.minute, | |
datetime.max.second, datetime.max.microsecond, tzinfo=pytz.UTC) | |
return init, final | |
def get_previus_month(month, year): | |
month -= 1 | |
if month <= 0: | |
month += 12 | |
year -= 1 | |
return month, year |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment