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


Python DateTime.week方法代码示例

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


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

示例1: getDateRangeFromWeek

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import week [as 别名]
    def getDateRangeFromWeek(self, start_week, start_year, end_week=None, end_year=None):
        """Returns tuple of DateTime. Compute this tuple from weeks. A week
        begins monday and ends sunday.
        """
        if end_week is None:
            end_week = start_week

        if end_year is None:
            end_year = start_year

        # Get first day of start year
        date_first_day = DateTime(start_year, 1, 1)
        day_minus = (date_first_day.dow() - 1) % 7
        day_plus = 0
        start_day = (start_week * 7) - 6 - day_minus
        start_date = DateTime(start_year, start_day)

        if start_date.week() != start_week:
            day_plus = 7
            start_date = start_date + day_plus

        # Get first day of end year
        date_first_day = DateTime(end_year, 1, 1)
        day_minus = (date_first_day.dow() - 1) % 7
        end_day = (end_week * 7) - day_minus + day_plus
        end_date = DateTime(end_year, end_day)

        # Finished at 23:59:59
        end_date = DateTime(end_date.year(),
                      end_date.month(),
                      end_date.day(),
                      23, 59, 59)

        return (start_date, end_date)
开发者ID:RedTurtle,项目名称:Products.PloneBooking,代码行数:36,代码来源:DateManager.py

示例2: testJulianWeek

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import week [as 别名]
 def testJulianWeek(self):
     # Check JulianDayWeek function
     fn = os.path.join(DATADIR, 'julian_testdata.txt')
     with open(fn, 'r') as fd:
         lines = fd.readlines()
     for line in lines:
         d = DateTime(line[:10])
         result_from_mx = tuple(map(int, line[12:-2].split(',')))
         self.assertEqual(result_from_mx[1], d.week())
开发者ID:chitaranjan,项目名称:Uber-Food-Trucks,代码行数:11,代码来源:test_datetime.py

示例3: testJulianWeek

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import week [as 别名]
    def testJulianWeek(self):
        # Check JulianDayWeek function
        try:
            import gzip
        except ImportError:
            print "Warning: testJulianWeek disabled: module gzip not found"
            return 0

        fn = os.path.join(DATADIR, 'julian_testdata.txt.gz')
        lines = gzip.GzipFile(fn).readlines()

        for line in lines:
            d = DateTime(line[:10])
            result_from_mx=tuple(map(int, line[12:-2].split(',')))
            self.assertEqual(result_from_mx[1], d.week())
开发者ID:goschtl,项目名称:zope,代码行数:17,代码来源:testDateTime.py

示例4: update

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import week [as 别名]
    def update(self):
        context = aq_inner(self.context)
        ptool = self.tools().properties()
        hours_per_day = ptool.xm_properties.getProperty('hours_per_day')
        request = self.request
        weeklist = []
        # Start at first day of the week.  Note: with the
        # DateTime.week() method Monday is considered the first day,
        # even though DateTime.dow() says Sunday is day zero.  To make
        # things worse, if say Sunday is 1 October, we want to start
        # with the week of Monday 25 September.

        # Go to the beginning of the week that has the first day of
        # this month.  How many days do we have to subtract for that?
        offset = self.startDate.dow() - 1
        if offset < 0:
            # Only happens for Sunday
            offset += 7

        if offset == 0:
            date = self.startDate
            year, month = self.year, self.month
        else:
            year, month = getPrevYearMonth(
                self.year, self.month)
            last_day = getEndOfMonth(year, month).day()
            date = DateTime(year, month, last_day - offset + 1)
        daynumber = date.day()
        # Assemble info for at most one month:
        ploneview = context.restrictedTraverse('@@plone')
        month_billable = 0.0
        month_worked_days = 0

        # When comparing dates, make sure December of previous year is
        # less than January of this year.
        while date.month() + 12 * date.year() <= self.month + 12 * self.year:
            weekinfo = dict(
                week_number=date.week(),
                week_start=ploneview.toLocalizedTime(date),
            )
            # Start the week cleanly
            day_of_week = 0
            daylist = []
            week_total = 0.0
            week_strict_total = 0.0
            days_bookings = DayBookingOverview(
                context, request, memberid=self.memberid)
            week_billable = 0.0
            week_worked_days = 0
            # Strict billable means: only count days of this week that
            # are really in this month.
            week_strict_billable = 0.0
            week_strict_worked_days = 0
            while day_of_week < 7:
                day_total = days_bookings.raw_total(date=date)
                day_billable = days_bookings.raw_billable(date=date)
                ui_class = 'greyed'
                if day_total > 0:
                    # Update week stats
                    week_total += day_total
                    if day_total != 0:
                        # Only add the billable hours to the week when
                        # some work (billable or not) has been done
                        # today.
                        week_billable += day_billable
                        week_worked_days += 1
                    if date.month() == self.startDate.month():
                        # Update strict stats
                        week_strict_total += day_total
                        week_strict_billable += day_billable
                        week_strict_worked_days += 1
                        # Update month stats
                        self.raw_total += day_total
                        if day_total != 0:
                            # Only add the billable hours to the month
                            # when some work (billable or not) has
                            # been done today.
                            month_billable += day_billable
                            month_worked_days += 1
                        ui_class = 'good'
                    else:
                        ui_class = 'greyed'
                    daylist.append(dict(total=formatTime(day_total),
                                        day_of_week=date.Day(),
                                        style=ui_class))
                else:
                    daylist.append(dict(total=None, day_of_week=date.Day(),
                                        style=ui_class))
                day_of_week += 1
                daynumber += 1
                try:
                    # We used to simply do date + 1, but that gave
                    # problems with Daylight Savings Time.
                    date = DateTime(year, month, daynumber)
                except DateTime.DateError:
                    # End of month reached, so go to the next.
                    daynumber = 1
                    year, month = getNextYearMonth(
                        year, month)
                    try:
#.........这里部分代码省略.........
开发者ID:zestsoftware,项目名称:Products.eXtremeManagement,代码行数:103,代码来源:bookings.py

示例5: DateTime

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import week [as 别名]
from Products.CMFCore.utils import getToolByName
from wres.policy.utils.utils import getWresSite
from DateTime import DateTime

today = DateTime()
last_update = today - today.week() - 1

return "Última atualização em " + last_update.strftime('%d/%m/%Y')

# vt = getToolByName(context,"vocabulary_tool")
# Versao = vt.get_vocabulary("cmed_version")
# DataVersao = vt.get_vocabulary("cmed_data")

# return "Versão {versao} de {data}".format(versao="".join(Versao), data="".join(DataVersao))
开发者ID:luizferreira,项目名称:cmed,代码行数:16,代码来源:getVersion.py


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