当前位置: 首页>>代码示例>>Python>>正文


Python Week.last_week_of_year方法代码示例

本文整理汇总了Python中isoweek.Week.last_week_of_year方法的典型用法代码示例。如果您正苦于以下问题:Python Week.last_week_of_year方法的具体用法?Python Week.last_week_of_year怎么用?Python Week.last_week_of_year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在isoweek.Week的用法示例。


在下文中一共展示了Week.last_week_of_year方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: week_display

# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import last_week_of_year [as 别名]
def week_display():
    # Default view is the current week. 
    if session.week is None:
        session.week = Week.thisweek()[1]
        session.year = date.today().year

    week = session.week
    year = session.year

    # some years end in week 53, others in week 52
    lastweekofyear = Week.last_week_of_year(year)[1]
    # If it is the last week of the year, fix forward button
    if lastweekofyear == week:
        forward = {"week":1,"year":year + 1}
    else:
        forward = {"week":week + 1,"year":year}
    # If it is the first week of the year, fix back button
    if week == 1:
        back = {"week":Week.last_week_of_year(year - 1)[1],"year":year - 1}
    else:
        back = {"week":week - 1,"year":year}

    # Our startdate will be current week, beginning with monday
    # set remaining sessions to new values and move on
    session.startday = Week(year, week).monday()
    session.back = back
    session.forward = forward
    session.week = week
    session.year = year 
开发者ID:rikardq,项目名称:rimi,代码行数:31,代码来源:instructor.py

示例2: test_constructors

# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import last_week_of_year [as 别名]
    def test_constructors(self):
        w = Week(2011,1)
        self.assertTrue(w)
        self.assertEqual(str(w), "2011W01")

        w = Week(2011,0)
        self.assertEqual(str(w), "2010W52")
        w = Week(2011,-1)
        self.assertEqual(str(w), "2010W51")

        w = Week(2011,52)
        self.assertEqual(str(w), "2011W52")
        w = Week(2011,53)
        self.assertEqual(str(w), "2012W01")
        w = Week(2011,54)
        self.assertEqual(str(w), "2012W02")

        w = Week(2009,51)
        self.assertEqual(str(w), "2009W51")
        w = Week(2009,52)
        self.assertEqual(str(w), "2009W52")
        w = Week(2009,53)
        self.assertEqual(str(w), "2010W01")
        w = Week(2009,54)
        self.assertEqual(str(w), "2010W02")

        w = Week.thisweek()
        self.assertTrue(w)

        w = Week.fromordinal(1)
        self.assertEqual(str(w), "0001W01")
        w = Week.fromordinal(2)
        self.assertEqual(str(w), "0001W02")
        w = Week.fromordinal(521723)
        self.assertEqual(str(w), "9999W52")

        w = Week.fromstring("2011W01")
        self.assertEqual(str(w), "2011W01")
        w = Week.fromstring("2011-W01")
        self.assertEqual(str(w), "2011W01")

        from datetime import date
        w = Week.withdate(date(2011, 5, 17))
        self.assertEqual(str(w), "2011W20")

        self.assertEqual(Week.last_week_of_year(2009), Week(2009, 52))
        self.assertEqual(Week.last_week_of_year(2010), Week(2010, 52))
        self.assertEqual(Week.last_week_of_year(2011), Week(2011, 52))
        self.assertEqual(Week.last_week_of_year(9999), Week(9999, 52))

        self.assertRaises(ValueError, lambda: Week(0, 0))
        self.assertRaises(ValueError, lambda: Week.fromstring("0000W00"))
        self.assertRaises(ValueError, lambda: Week.fromstring("foo"))
        self.assertRaises(ValueError, lambda: Week.fromordinal(-1))
        self.assertRaises(ValueError, lambda: Week.fromordinal(0))
        self.assertRaises(ValueError, lambda: Week.fromordinal(521724))
        self.assertRaises(ValueError, lambda: Week.last_week_of_year(0))
        self.assertRaises(ValueError, lambda: Week.last_week_of_year(10000))
开发者ID:mcgarryfashion,项目名称:isoweek,代码行数:60,代码来源:test_isoweek.py


注:本文中的isoweek.Week.last_week_of_year方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。