本文整理汇总了Python中isoweek.Week.day方法的典型用法代码示例。如果您正苦于以下问题:Python Week.day方法的具体用法?Python Week.day怎么用?Python Week.day使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类isoweek.Week
的用法示例。
在下文中一共展示了Week.day方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tracking_calendar
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import day [as 别名]
def tracking_calendar(request, year=None, week=None):
'''
This view will get parameters from url and will try to generate
a table of the current week where reminders we get can be tracked.
'''
# If there is no year we generate it
if year == None:
ryear = date.today().year
else:
ryear = int(year)
# The same with the week
if week == None:
rweek = date.today().isocalendar()[1]
else:
rweek = int(week)
# If someone tries to insert manually a week which doesn't exist
# we return him/her a 403 page (have to change with something else).
if rweek > '53':
raise PermissionDenied()
isoweek = Week(ryear, rweek)
sqlweek = []
for x in range(5):
sqlweek.append(isoweek.day(x))
try:
RemindersTable.objects.get(rday=isoweek.day(0))
except RemindersTable.DoesNotExist:
for x in range(5):
RemindersTable.objects.create(rday=isoweek.day(x))
tableresults = []
dayrow = []
for day in sqlweek:
weekresults = RemindersTable.objects.filter(rday=day)
for value in weekresults.values_list()[0]:
dayrow.append(value)
tableresults.append(dayrow)
dayrow = []
headers = weekresults.values().field_names
return render_to_response("calendar.html", {'sqlweek': sqlweek,
'headers': headers,
'tableresults': tableresults}, RequestContext(request))
示例2: test_days
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import day [as 别名]
def test_days(self):
w = Week(2011, 20)
self.assertEqual(w.monday().isoformat(), "2011-05-16")
self.assertEqual(w.tuesday().isoformat(), "2011-05-17")
self.assertEqual(w.wednesday().isoformat(), "2011-05-18")
self.assertEqual(w.thursday().isoformat(), "2011-05-19")
self.assertEqual(w.friday().isoformat(), "2011-05-20")
self.assertEqual(w.saturday().isoformat(), "2011-05-21")
self.assertEqual(w.sunday().isoformat(), "2011-05-22")
self.assertEqual(w.day(0).isoformat(), "2011-05-16")
self.assertEqual(w.day(-1).isoformat(), "2011-05-15")
self.assertEqual(w.day(10).isoformat(), "2011-05-26")
days = w.days()
self.assertEqual(len(days), 7)
self.assertEqual(days[0].isoformat(), "2011-05-16")
self.assertEqual(days[-1].isoformat(), "2011-05-22")
from datetime import date
self.assertFalse(w.contains(date(2011,5,15)))
self.assertTrue(w.contains(date(2011,5,16)))
self.assertTrue(w.contains(date(2011,5,22)))
self.assertFalse(w.contains(date(2011,5,23)))
示例3: get_year_ago
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import day [as 别名]
def get_year_ago(self, dia=None, yearsago=None):
if not dia:
dia = self.day_present
years_ago = self.years_ago
if yearsago:
years_ago = int(yearsago)
logger.debug("Calculating {} year ago for {}".format(years_ago, dia))
current = dia.isocalendar() # 0 year, 1 week, 2, weekday
year = current[0]
week = current[1]
weekday = current[2] - 1 # Isocalendar uses american weekdays
week_current = Week(year, week)
week_past = week_current.replace(year - years_ago, week)
past_new = self.ensure_same_day_scenario(
week_current, week_past, weekday)
if past_new:
self.day_year_ago = datetime.combine(past_new, datetime.min.time())
else:
self.day_year_ago = datetime.combine(
week_past.day(weekday), datetime.min.time())
logger.debug("SUMMARY")
logger.debug(" - Present day: {}".format(week_current.day(weekday)))
logger.debug(" - Past day ini: {}".format(week_past.day(weekday)))
logger.debug(
" - Past day correction: {}".format(self.day_year_ago.strftime("%Y-%m-%d")))
logger.info("{} year ago from {} was {}" .format(years_ago, self.day_present.strftime(
"%Y-%m-%d"), self.day_year_ago.strftime("%Y-%m-%d")))
return self.day_year_ago