示例#1
0
 def iteryearmonths(self):
     """
     Uses calendar.nextmonth to get all (year, month) pairs between
     the start date and end date inclusive.
     """
     months = []
     current = (self.begdate.year, self.begdate.month)
     enddate = calendar.nextmonth(self.enddate.year, self.enddate.month)
     while current != enddate:
         months.append(current)
         current = calendar.nextmonth(*current)
     return months
示例#2
0
    def month_iterator(self, document):
        ym = datetime.datetime(document.period_start.year,
                               document.period_start.month,
                               document.period_start.day)

        end = document.period_end
        while self.ym_to_num(ym) <= self.ym_to_num(end):
            yield ym
            next_y, next_m = calendar.nextmonth(ym.year, ym.month)
            ym = datetime.datetime(next_y, next_m, 1)
示例#3
0
def get_all_expirty_date_within_range(from_date,to_date):
	num_months = (to_date.year - from_date.year) * 12 + (to_date.month - from_date.month) + 2
	current_date = from_date
	monthly_expiries = []
	for month in range(0,num_months):
		monthly_expiries.append(get_expiry_date(current_date.year,current_date.month,False,True))
		next_month = calendar.nextmonth(current_date.year,current_date.month)
		current_date = datetime(next_month[0],next_month[1],1).date()

	flttern_monthly_expiries = list(itertools.chain.from_iterable(monthly_expiries))
	return flttern_monthly_expiries
示例#4
0
    def __init__(self):
        # read meals
        file = 'meals'
        self.meals = pd.read_csv('input/' + file + '.csv', delimiter=',')

        # define the month
        tdy = date.today()
        nxt_month = calendar.nextmonth(tdy.year, tdy.month)[1]
        yr = calendar.nextmonth(tdy.year, tdy.month)[0]
        last_day_of_month = calendar.monthrange(yr, nxt_month)[1]
        # fix month into proper format
        nxt_month = ffmp.fx_month(nxt_month)
        start_date = str(yr) + '-' + str(nxt_month) + '-0' + str(1)
        end_date = str(yr) + '-' + str(nxt_month) + '-' + str(
            last_day_of_month)
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
        # create date range
        data = pd.DataFrame(pd.date_range(start_date, end_date))
        data.columns = ['dates']
        data['Weekday'] = data.dates.dt.dayofweek
        self.data = data.loc[(data.Weekday < 5)]
        # create meals per each category
        self.meat = list(self.meals.Meal_Id.loc[self.meals.Category == 'Meat'])
        self.chicken = list(
            self.meals.Meal_Id.loc[self.meals.Category == 'Chicken'])
        self.fish = list(self.meals.Meal_Id.loc[self.meals.Category == 'Fish'])
        self.vegan = list(
            self.meals.Meal_Id.loc[self.meals.Category == 'Vegan'])
        self.veggie = list(
            self.meals.Meal_Id.loc[self.meals.Category == 'Vegetarian'])

        # Create Diet DataFrames
        self.omni_diet = self.meals.Meal_Id.loc[self.meals.Omnivore == 1]
        self.pescat_diet = self.meals.Meal_Id.loc[self.meals.Pescatarian == 1]
        self.vegan_diet = self.meals.Meal_Id.loc[self.meals.Vegan == 1]
        self.veggie_diet = self.meals.Meal_Id.loc[self.meals.Vegetarian == 1]
示例#5
0
    def swipe_month(self, previous=False):
        """
        Implements the swipe mechanism

        :param previous: if True set month to previous, otherwise to the next
        :return: None
        """
        day = datetime(month=self.current_month.get(),
                       year=self.current_year.get(),
                       day=1)
        month = calendar.prevmonth(month=day.month, year=day.year) \
            if previous \
            else calendar.nextmonth(month=day.month, year=day.year)

        self.current_year.set(month[0])
        self.current_month.set(month[1])

        self.clear_calendar()
        self.render_month(month=month[1], year=month[0])
示例#6
0
def get_range_date(year, month, day) -> tuple:
    """
    Retorna un rango de fecha con una diferencia de
        - Un año.
        - Un mes.
        - Un dia.
    Segun la especificacion de la entrada
    """
    from_date = timezone.datetime(year=year,
                                  month=month if month else 1,
                                  day=day if day else 1)
    if not month:
        to_date = timezone.datetime(year=year + 1, month=1, day=1)
    elif day:
        to_date = timezone.datetime(year=year, month=month,
                                    day=day) + timezone.timedelta(days=1)
    else:
        to_year, to_month = calendar.nextmonth(year=year, month=month)
        to_date = timezone.datetime(year=to_year, month=to_month, day=1)

    return from_date, to_date
示例#7
0
"""

print("##################### 4 #####################")
print("monthlen:", calendar.monthlen(2018, 10))
print("monthlen:", calendar.monthlen(2018, 11))
print("monthlen:", calendar.monthlen(2018, 12))
"""
output:
    monthlen: 31
    monthlen: 30
    monthlen: 31
"""

print("##################### 5 #####################")
print("prevmonth:", calendar.prevmonth(2018, 11))
print("nextmonth:", calendar.nextmonth(2018, 11))
"""
output:
    prevmonth: (2018, 10)
    nextmonth: (2018, 12)
"""

print("##################### 6 #####################")
print("monthrange:", calendar.monthrange(2018, 10))
print("monthrange:", calendar.monthrange(2018, 11))
print("monthrange:", calendar.monthrange(2018, 12))
"""
output:
    monthrange: (0, 31)
    monthrange: (3, 30)
    monthrange: (5, 31)
示例#8
0
import calendar
print(calendar.month(2018, 12))
print(calendar.nextmonth(2018, 5))
print(calendar.calendar(2012))
示例#9
0
we will have import calender library
this library .or module includes several function we take a look  at few of them

'''
#import calender module
import calendar

date = input("enter the date(dd/mm/year): ")

day, month, year = date.split("/")

day = int(day)
month = int(month)
year = int(year)

#print("calender of month ", month, " of year ", year)
print(calendar.month(year, month))

print("month length: ", calendar.monthlen(year, month))

print("next month: ", calendar.nextmonth(year, month))

print("previous month: ", calendar.prevmonth(year, month))

print("week day(week start from monday):", calendar.weekday(year, month, day))
'''
let's have a look at few more basic functions

thank you for watching
'''
示例#10
0
    client = Socrata("data.cityofchicago.org", apitoken, username, pwd)
    # automatic timeout is 10s, increase to 2 hours
    client.timeout = 7200

    for y, m in [(i.year, i.month)
                 for i in pd.period_range(start_date, end_date, freq="M")]:
        print("Downloading %d-%d" % (y, m))

        time = datetime.datetime.now()
        # slow
        # results = client.get("m6dm-c72p", where="date_extract_y(trip_start_timestamp) = " + str(y) +" AND date_extract_m(trip_start_timestamp)= " + str(m), content_type="csv", limit=2000)
        if m < 10:
            pad = '0'
        else:
            pad = ''
        (y1, m1) = calendar.nextmonth(year=y, month=m)
        if m1 < 10:
            pad1 = '0'
        else:
            pad1 = ''

        s = str(y) + '-' + pad + str(m) + '-01'
        e = str(y1) + '-' + pad1 + str(m1) + '-01'

        d = calendar.monthrange(y, m)[1]

        results = client.get_all("m6dm-c72p",
                                 where="trip_start_timestamp >= \"" + s +
                                 "\" AND trip_start_timestamp < \"" + e + "\"",
                                 content_type="csv")
示例#11
0
import calendar

print(calendar.weekheader(3))
print(calendar.firstweekday())
print(calendar.month(2020, 1))
print(calendar.weekday(2020, 1, 15))
print(calendar.nextmonth(2020, 1))
print(calendar.calendar(2019))
day = calendar.weekday(2020, 1, 15)
print(day)
示例#12
0
 def next_month(self):
     '''Move one month forward'''
     self.year, self.month = calendar.nextmonth(self.year, self.month)
     self.day = 1
     self.populate_func()