def _populate(self, year): # Populate the holiday list with the default US holidays holidays.UnitedStates._populate(self, year) # Remove Columbus Day # self.pop(date(year, 10, 1) + relativedelta(weekday=MO(+2)), None) # Add Valentines Day self[date(year, 2, 14)] = "Valentines Day" self[date(year, 1, 1) + relativedelta(weekday=MO(+3))] = "Martin Luther King Day" self[date(year, 2, 1) + relativedelta(weekday=MO(+3))] = "President's Day" self[date(year, 5, 1) + relativedelta(weekday=SU(+2))] = "Mother's Day" self[date(year, 6, 1) + relativedelta(weekday=SU(+3))] = "Father's Day" self[date(year, 10, 31)] = "Halloween"
def report_time_by_user_by_week_date(self, from_date, to_date, user): start_date = from_date + relativedelta(weekday=SU(-1)) end_date = to_date + relativedelta(weekday=SU(1)) result = collections.OrderedDict() for d in rrule(WEEKLY, dtstart=start_date, until=end_date): result[d.date()] = 0 qs = TimeRecord.objects.filter( date_started__gte=from_date, date_started__lte=to_date, user=user, ) for row in qs: if row.is_complete: item = row.date_started + relativedelta(weekday=SU(-1)) result[item] = result[item] + row.minutes return result
def test_str(self): rr = Recurrence(dtstart=datetime(2009, 1, 1), freq=WEEKLY, count=9, byweekday=[MO, TU, WE, TH, FR]) self.assertEqual(str(rr), "DTSTART:20090101\n" \ "RRULE:FREQ=WEEKLY;WKST=SU;COUNT=9;BYDAY=MO,TU,WE,TH,FR") self.assertEqual(rr.count, rr.getCount()) rr = Recurrence(dtstart=datetime(2011, 1, 1), freq=DAILY, interval=2, until=datetime(2011, 1, 11)) self.assertEqual(str(rr), "DTSTART:20110101\n" \ "RRULE:FREQ=DAILY;INTERVAL=2;WKST=SU;UNTIL=20110111") rr = Recurrence(dtstart=datetime(2012, 1, 1), freq=YEARLY, bymonth=[1, 2], byweekday=range(7), until=datetime(2012, 1, 31)) self.assertEqual(str(rr), "DTSTART:20120101\n" \ "RRULE:FREQ=YEARLY;WKST=SU;UNTIL=20120131;" \ "BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1,2") rr = Recurrence(dtstart=datetime(2015, 10, 1), freq=MONTHLY, bymonth=range(1, 12), byweekday=[(SU(-1))]) self.assertEqual(str(rr), "DTSTART:20151001\n" \ "RRULE:FREQ=MONTHLY;WKST=SU;BYDAY=-1SU;BYMONTH=1,2,3,4,5,6,7,8,9,10,11")
def get_context(self, request): context = super(DBSPage, self).get_context(request) today = datetime.now() next = rrule(YEARLY, dtstart=now, byweekday=SU(1), bymonth=7, count=10) context['next'] = [] for n in next: context.netxt.append(n - relativedelta(days=-1)) return context
def get_mothers_day_date(year): """Given the passed in year int, return the date Mother's Day is celebrated assuming it's the 2nd Sunday of May.""" mothers_day_list = list(rrule(YEARLY, count=11, bymonth=5, byweekday=SU(2), dtstart=date(2014, 1, 1))) for i in mothers_day_list: if i.year == year: return i.date() pass
def get_mothers_day_date(year): """Given the passed in year int, return the date Mother's Day is celebrated assuming it's the 2nd Sunday of May.""" return list( rrule(YEARLY, dtstart=date(year, 1, 1), count=1, bymonth=5, byweekday=SU(+2)))[0].date()
def build_list_of_shifts(start): """ Starting with the Monday following the start date specified by the user, build a list of twelve on-call shifts that run Monday to Sunday. """ i = 1 lst = [] for monday in range(12): monday = start + relativedelta(weekday=MO(+i)) sunday = start + relativedelta(weekday=SU(+i + 1)) lst.append(str(monday) + " - " + str(sunday)) i += 1 return lst
from datetime import datetime from dateutil.rrule import rrule, YEARLY, SU # Daylight savings time starts on the second Sunday in March. DST_STARTS = set(dt.date() for dt in rrule(YEARLY, bymonth=3, byweekday=SU(2), dtstart=datetime(2000, 1, 1), count=100)) # Daylight savings time ends on the first Sunday in November. DST_ENDS = set(dt.date() for dt in rrule(YEARLY, bymonth=11, byweekday=SU(1), dtstart=datetime(2000, 1, 1), count=100))
def getTimezone(date): """ Returns the timezone of a date ... Parameters ---------- datetime : date The date to check Returns ------- datetime.tzinfo timezone """ last_SU_march = date + relativedelta(month=3,day=31,hour=2,minute=0,second=0, weekday=SU(-1)) last_SU_oct = date + relativedelta(month=10,day=31,hour=3,minute=0,second=0, weekday=SU(-1)) if (date < last_SU_march) or (date > last_SU_oct): return CET() else: return CEST()
zh_hans="青年节", zh_hant="青年節", ) NurseDay = Festival( lambda year: datetime.date(year, 5, 12), en="International Nurses Day", zh_hans="护士节", zh_hant="護士節", ) MotherDay = Festival( lambda year: rrule(MONTHLY, count=1, bymonth=5, byweekday=SU(2), dtstart=datetime.datetime(year, 5, 1))[0].date(), en="Mother's Day", zh_hans="母亲节", zh_hant="母親節", ) ChildrenDay = Festival( lambda year: datetime.date(year, 6, 1), en="Children's Day", zh_hans="儿童节", zh_hant="兒童節", ) FatherDay = Festival( lambda year: rrule(MONTHLY,