python类hour()的实例源码

ver_32.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def replace(self, hour=None, minute=None, second=None, microsecond=None, delta_hour=0, delta_minute=0, delta_second=0):
        if not self:
            return self.__class__._null_time
        old_hour, old_minute, old_second, old_micro = self.hour, self.minute, self.second, self.microsecond
        hour = (hour or old_hour) + delta_hour
        minute = (minute or old_minute) + delta_minute
        second = (second or old_second) + delta_second
        microsecond = microsecond or old_micro
        while not (0 <= hour < 24) or not (0 <= minute < 60) or not (0 <= second < 60):
            while second < 0:
                minute -= 1
                second = 60 + second
            while second > 59:
                minute += 1
                second = second - 60
            while minute < 0:
                hour -= 1
                minute = 60 + minute
            while minute > 59:
                hour += 1
                minute = minute - 60
            while hour < 1:
                hour = 24 + hour
            while hour > 23:
                hour = hour - 24
        return Time(hour, minute, second, microsecond)
ver_32.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __init__(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None):
        params = vars()
        self._mask = {}
        for attr in ('year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond'):
            value = params[attr]
            if value is not None:
                self._mask[attr] = value
ver_32.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __repr__(self):
        items = []
        for attr in ('year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond'):
            if attr in self._mask:
                items.append('%s=%s' % (attr, self._mask[attr]))
        return "Period(%s)" % ', '.join(items)
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def time(self):
        if self:
            return Time(self.hour, self.minute, self.second, self.microsecond)
        return Time()
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __add__(self, other):
        if self and isinstance(other, (datetime.timedelta)):
            t = self._time
            t = datetime.datetime(2012, 6, 27, t.hour, t.minute, t.second, t.microsecond)
            t += other
            return Time(t.hour, t.minute, t.second, t.microsecond)
        else:
            return NotImplemented
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __rsub__(self, other):
        if self and isinstance(other, (Time, datetime.time)):
            t = self._time
            t = datetime.datetime(2012, 6, 27, t.hour, t.minute, t.second, t.microsecond)
            other = datetime.datetime(2012, 6, 27, other.hour, other.minute, other.second, other.microsecond)
            other -= t
            return other
        else:
            return NotImplemented
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __repr__(self):
        if self:
            return "Time(%d, %d, %d, %d)" % (self.hour, self.minute, self.second, self.microsecond)
        else:
            return "Time()"
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def replace(self, hour=None, minute=None, second=None, microsecond=None, delta_hour=0, delta_minute=0, delta_second=0):
        if not self:
            return self.__class__._null_time
        old_hour, old_minute, old_second, old_micro = self.hour, self.minute, self.second, self.microsecond
        hour = (hour or old_hour) + delta_hour
        minute = (minute or old_minute) + delta_minute
        second = (second or old_second) + delta_second
        microsecond = microsecond or old_micro
        while not (0 <= hour < 24) or not (0 <= minute < 60) or not (0 <= second < 60):
            while second < 0:
                minute -= 1
                second = 60 + second
            while second > 59:
                minute += 1
                second = second - 60
            while minute < 0:
                hour -= 1
                minute = 60 + minute
            while minute > 59:
                hour += 1
                minute = minute - 60
            while hour < 1:
                hour = 24 + hour
            while hour > 23:
                hour = hour - 24
        return Time(hour, minute, second, microsecond)
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def tofloat(self):
        "returns Time as a float"
        hour = self.hour
        minute = self.minute * (1.0 / 60)
        second = self.second * (1.0 / 3600)
        microsecond = self.microsecond * (1.0 / 3600000)
        return hour + minute + second + microsecond
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None):
        params = vars()
        self._mask = {}
        for attr in ('year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond'):
            value = params[attr]
            if value is not None:
                self._mask[attr] = value
ver_2.py 文件源码 项目:dbf 作者: wenzhihong2003 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __repr__(self):
        items = []
        for attr in ('year', 'month', 'day', 'hour', 'minute', 'second', 'microsecond'):
            if attr in self._mask:
                items.append('%s=%s' % (attr, self._mask[attr]))
        return "Period(%s)" % ', '.join(items)
live_scoreboard.py 文件源码 项目:live_scoreboard 作者: ClysmiC 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def toTwelveHourClock(time):
    newHour = time.hour
    suffix = "PM"

    if (newHour > 12):
        newHour -= 12
    else:
        if(newHour == 0):
            newHour = 12

        suffix = "AM"

    return newHour, suffix
live_scoreboard.py 文件源码 项目:live_scoreboard 作者: ClysmiC 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def requestWeatherData(self):
        # If internet has been out for an hour, there is already a
        # thread still running trying to get the data
        if self.__weatherThread is None or not self.__weatherThread.isAlive():
            self.__weatherThread = threading.Thread(target=self.__asyncRequestWeatherData)
            self.__weatherThread.start()
live_scoreboard.py 文件源码 项目:live_scoreboard 作者: ClysmiC 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def update(self):
        self.canvas.delete("updates")

        string1 = daysOfWeek[self.dateAndTime.weekday()] + ", " + months[self.dateAndTime.month] + " " + str(self.dateAndTime.day)

        if TWENTY_FOUR_HOUR_CLOCK:
            string2 = "{:02d}:{:02d}:{:02d}".format(self.dateAndTime.hour, self.dateAndTime.minute, self.dateAndTime.second)
        else:
            hour, suffix = toTwelveHourClock(self.dateAndTime)
            string2 = "{:02d}:{:02d}:{:02d} {:s}".format(hour, self.dateAndTime.minute, self.dateAndTime.second, suffix)

        self.canvas.create_text((self.width // 2, self.height * .30), text=string1, fill=fontColor, font=self.font, tags="updates")
        self.canvas.create_text((self.width // 2, self.height * .70), text=string2, fill=fontColor, font=self.font, tags="updates")
live_scoreboard.py 文件源码 项目:live_scoreboard 作者: ClysmiC 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def update(self):
        self.canvas.delete("updates")
        self.show()

        if self.game["status"] == "Pre":
            topString = "{:3s} @ {:3s}".format(self.game["away"]["name"], self.game["home"]["name"])

            ast = self.game["adjustedStartTime"]


            if TWENTY_FOUR_HOUR_CLOCK:
                botString = "{:s} {:d}, {:02d}:{:02d}".format(months[ast.month], ast.day, ast.hour, ast.minute)
            else:
                hour, suffix = toTwelveHourClock(ast)
                botString = "{:s} {:d}, {:02d}:{:02d} {:s}".format(months[ast.month], ast.day, hour, ast.minute, suffix)


            awayLogo = self.scaledLogos[self.game["away"]["name"]]
            homeLogo = self.scaledLogos[self.game["home"]["name"]]

            # Center logo
            awayLogoXOffset = (self.awayLogoRegion.width - awayLogo.width()) // 2
            awayLogoYOffset = (self.awayLogoRegion.height - awayLogo.height()) // 2

            homeLogoXOffset = (self.homeLogoRegion.width - homeLogo.width()) // 2
            homeLogoYOffset = (self.homeLogoRegion.height - homeLogo.height()) // 2

            lineY = self.lineYStart

            self.canvas.create_image((self.awayLogoRegion.left + awayLogoXOffset, self.awayLogoRegion.top + awayLogoYOffset), anchor=tk.NW, image=awayLogo, tags="updates")
            self.canvas.create_image((self.homeLogoRegion.left + homeLogoXOffset, self.homeLogoRegion.top + homeLogoYOffset), anchor=tk.NW, image=homeLogo, tags="updates")

            self.canvas.create_text((self.topX, lineY), anchor=tk.NW, text=topString, font=self.font, fill=fontColor, tags="updates")

            lineY += self.lineHeight

            self.canvas.create_text((self.botX, lineY), anchor=tk.NW, text=botString, font=self.font, fill=fontColor, tags="updates")
        else:
            self.canvas.create_text((self.width // 2, self.height //2), anchor=tk.CENTER, text="No games found...", font=self.font, fill=fontColor, tags="updates")
datetime_safe.py 文件源码 项目:Deploy_XXNET_Server 作者: jzp820927 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def combine(self, date, time):
        return datetime(date.year, date.month, date.day, time.hour, time.minute, time.microsecond, time.tzinfo)
datetime_safe.py 文件源码 项目:Deploy_XXNET_Server 作者: jzp820927 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def new_datetime(d):
    """
    Generate a safe datetime from a datetime.date or datetime.datetime object.
    """
    kw = [d.year, d.month, d.day]
    if isinstance(d, real_datetime):
        kw.extend([d.hour, d.minute, d.second, d.microsecond, d.tzinfo])
    return datetime(*kw)

# This library does not support strftime's "%s" or "%y" format strings.
# Allowed if there's an even number of "%"s because they are escaped.
dateandtime.py 文件源码 项目:jabbapylib3 作者: jabbalaci 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_time():
    """
    Current time (HHMM).

    The return value is a string.
    """
    now = datetime.now()
    time = datetime.time(now)
    return "{hour:02}{minute:02}".format(hour=time.hour, minute=time.minute)
test.py 文件源码 项目:rarebot 作者: RaRe-Technologies 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def prepLine(lineDict, mappings):
    result = []
    if lineDict['category'] in mappings['category']:
        result.append(mappings['category'].index(lineDict['category']))
    else:
        result.append(-1)

    if lineDict['behaviour'] in mappings['behaviour']:
        result.append(mappings['behaviour'].index(lineDict['behaviour']))
    else:
        result.append(-1)

    if lineDict['connection'] in mappings['connection']:
        result.append(mappings['connection'].index(lineDict['connection']))
    else:
        result.append(-1)

    day = datetime.datetime.fromtimestamp(lineDict['unix_timestamp']).weekday()
    time = datetime.datetime.fromtimestamp(lineDict['unix_timestamp']).time()
    seconds = time.hour*3600 + time.minute*60 + time.second
    result.append(day)
    result.append(seconds)
    #result.append(time.hour)

    if lineDict['safe_connection'] in mappings['safe_connection']:
        result.append(mappings['safe_connection'].index(lineDict['safe_connection']))
    else:
        result.append(-1)
    return [result] # wrap result in a list to be directly usable in model.predict (todo: test if it is necessary)
feeds.py 文件源码 项目:partytime 作者: sunlightlabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _date_time_to_datetime(date, time=None):
    if not time:
        time = datetime.time()
    return datetime.datetime(date.year, date.month, date.day, time.hour, time.minute, time.second)


问题


面经


文章

微信
公众号

扫码关注公众号