本文整理汇总了Python中isoweek.Week.replace方法的典型用法代码示例。如果您正苦于以下问题:Python Week.replace方法的具体用法?Python Week.replace怎么用?Python Week.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类isoweek.Week
的用法示例。
在下文中一共展示了Week.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_replace
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import replace [as 别名]
def test_replace(self):
w = Week(2011, 20)
self.assertEqual(w.replace(), w)
self.assertEqual(w.replace(year=2010), Week(2010, 20))
self.assertEqual(w.replace(week=2), Week(2011, 2))
self.assertEqual(w.replace(week=99), Week(2012, 47))
self.assertEqual(w.replace(year=1, week=1), Week(1, 1))
示例2: get_year_ago
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import replace [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