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


Python time.time方法代码示例

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


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

示例1: to_param_put

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def to_param_put(self):
        """
        convert dev_info to ParamPutRequest message.
        :rtype : ParamPutRequest
        """
        req = ParamPutRequest(self.station_no)
        req.rec_interval = self.rec_interval or time(0, 0, 30)
        req.upper_limit = self.upper_limit
        req.lower_limit = self.lower_limit
        req.update_station_no = self.station_no
        req.stop_button = self.stop_button
        req.delay = self.delay
        req.tone_set = self.tone_set
        req.alarm = self.alarm
        req.temp_unit = self.temp_unit
        req.temp_calibration = self.temp_calibration
        req.humi_upper_limit = self.humi_upper_limit
        req.humi_lower_limit = self.humi_lower_limit
        req.humi_calibration = self.humi_calibration

        return req 
开发者ID:civic,项目名称:elitech-datareader,代码行数:23,代码来源:msg.py

示例2: __init__

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def __init__(self, target_station_no):
        self.target_station_no = target_station_no
        self.rec_interval = time(0, 10, 0)

        self.upper_limit = 60.0
        self.lower_limit = -30.0
        self.update_station_no = 1

        self.stop_button = StopButton.DISABLE
        self.delay = 0
        self.tone_set = ToneSet.NONE
        self.alarm = AlarmSetting.NONE
        self.temp_unit = TemperatureUnit.C
        self.temp_calibration = 0
        self.humi_upper_limit = 0
        self.humi_lower_limit = 0
        self.humi_calibration = 0 
开发者ID:civic,项目名称:elitech-datareader,代码行数:19,代码来源:msg.py

示例3: test_pickling_subclass

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_pickling_subclass(self):
        # Make sure we can pickle/unpickle an instance of a subclass.
        offset = timedelta(minutes=-300)
        orig = PicklableFixedOffset(offset, 'cookie')
        self.assertIsInstance(orig, tzinfo)
        self.assertTrue(type(orig) is PicklableFixedOffset)
        self.assertEqual(orig.utcoffset(None), offset)
        self.assertEqual(orig.tzname(None), 'cookie')
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIsInstance(derived, tzinfo)
            self.assertTrue(type(derived) is PicklableFixedOffset)
            self.assertEqual(derived.utcoffset(None), offset)
            self.assertEqual(derived.tzname(None), 'cookie')

#############################################################################
# Base class for testing a particular aspect of timedelta, time, date and
# datetime comparisons. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_datetime.py

示例4: test_extreme_ordinals

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_extreme_ordinals(self):
        a = self.theclass.min
        a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
        aord = a.toordinal()
        b = a.fromordinal(aord)
        self.assertEqual(a, b)

        self.assertRaises(ValueError, lambda: a.fromordinal(aord - 1))

        b = a + timedelta(days=1)
        self.assertEqual(b.toordinal(), aord + 1)
        self.assertEqual(b, self.theclass.fromordinal(aord + 1))

        a = self.theclass.max
        a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
        aord = a.toordinal()
        b = a.fromordinal(aord)
        self.assertEqual(a, b)

        self.assertRaises(ValueError, lambda: a.fromordinal(aord + 1))

        b = a - timedelta(days=1)
        self.assertEqual(b.toordinal(), aord - 1)
        self.assertEqual(b, self.theclass.fromordinal(aord - 1)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_datetime.py

示例5: test_backdoor_resistance

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_backdoor_resistance(self):
        # For fast unpickling, the constructor accepts a pickle string.
        # This is a low-overhead backdoor.  A user can (by intent or
        # mistake) pass a string directly, which (if it's the right length)
        # will get treated like a pickle, and bypass the normal sanity
        # checks in the constructor.  This can create insane objects.
        # The constructor doesn't want to burn the time to validate all
        # fields, but does check the month field.  This stops, e.g.,
        # datetime.datetime('1995-03-25') from yielding an insane object.
        base = '1995-03-25'
        if not issubclass(self.theclass, datetime):
            base = base[:4]
        for month_byte in '9', chr(0), chr(13), '\xff':
            self.assertRaises(TypeError, self.theclass,
                                         base[:2] + month_byte + base[3:])
        for ord_byte in range(1, 13):
            # This shouldn't blow up because of the month byte alone.  If
            # the implementation changes to do more-careful checking, it may
            # blow up because other fields are insane.
            self.theclass(base[:2] + chr(ord_byte) + base[3:])

#############################################################################
# datetime tests 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_datetime.py

示例6: test_combine

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_combine(self):
        d = date(2002, 3, 4)
        t = time(18, 45, 3, 1234)
        expected = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
        combine = self.theclass.combine
        dt = combine(d, t)
        self.assertEqual(dt, expected)

        dt = combine(time=t, date=d)
        self.assertEqual(dt, expected)

        self.assertEqual(d, dt.date())
        self.assertEqual(t, dt.time())
        self.assertEqual(dt, combine(dt.date(), dt.time()))

        self.assertRaises(TypeError, combine) # need an arg
        self.assertRaises(TypeError, combine, d) # need two args
        self.assertRaises(TypeError, combine, t, d) # args reversed
        self.assertRaises(TypeError, combine, d, t, 1) # too many args
        self.assertRaises(TypeError, combine, "date", "time") # wrong types 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_datetime.py

示例7: test_argument_passing

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_argument_passing(self):
        cls = self.theclass
        # A datetime passes itself on, a time passes None.
        class introspective(tzinfo):
            def tzname(self, dt):    return dt and "real" or "none"
            def utcoffset(self, dt):
                return timedelta(minutes = dt and 42 or -42)
            dst = utcoffset

        obj = cls(1, 2, 3, tzinfo=introspective())

        expected = cls is time and "none" or "real"
        self.assertEqual(obj.tzname(), expected)

        expected = timedelta(minutes=(cls is time and -42 or 42))
        self.assertEqual(obj.utcoffset(), expected)
        self.assertEqual(obj.dst(), expected) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_datetime.py

示例8: convert_between_tz_and_utc

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def convert_between_tz_and_utc(self, tz, utc):
        dston = self.dston.replace(tzinfo=tz)
        # Because 1:MM on the day DST ends is taken as being standard time,
        # there is no spelling in tz for the last hour of daylight time.
        # For purposes of the test, the last hour of DST is 0:MM, which is
        # taken as being daylight time (and 1:MM is taken as being standard
        # time).
        dstoff = self.dstoff.replace(tzinfo=tz)
        for delta in (timedelta(weeks=13),
                      DAY,
                      HOUR,
                      timedelta(minutes=1),
                      timedelta(microseconds=1)):

            self.checkinside(dston, tz, utc, dston, dstoff)
            for during in dston + delta, dstoff - delta:
                self.checkinside(during, tz, utc, dston, dstoff)

            self.checkoutside(dstoff, tz, utc)
            for outside in dston - delta, dstoff + delta:
                self.checkoutside(outside, tz, utc) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_datetime.py

示例9: test_easy

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_easy(self):
        # Despite the name of this test, the endcases are excruciating.
        self.convert_between_tz_and_utc(Eastern, utc_real)
        self.convert_between_tz_and_utc(Pacific, utc_real)
        self.convert_between_tz_and_utc(Eastern, utc_fake)
        self.convert_between_tz_and_utc(Pacific, utc_fake)
        # The next is really dancing near the edge.  It works because
        # Pacific and Eastern are far enough apart that their "problem
        # hours" don't overlap.
        self.convert_between_tz_and_utc(Eastern, Pacific)
        self.convert_between_tz_and_utc(Pacific, Eastern)
        # OTOH, these fail!  Don't enable them.  The difficulty is that
        # the edge case tests assume that every hour is representable in
        # the "utc" class.  This is always true for a fixed-offset tzinfo
        # class (lke utc_real and utc_fake), but not for Eastern or Central.
        # For these adjacent DST-aware time zones, the range of time offsets
        # tested ends up creating hours in the one that aren't representable
        # in the other.  For the same reason, we would see failures in the
        # Eastern vs Pacific tests too if we added 3*HOUR to the list of
        # offset deltas in convert_between_tz_and_utc().
        #
        # self.convert_between_tz_and_utc(Eastern, Central)  # can't work
        # self.convert_between_tz_and_utc(Central, Eastern)  # can't work 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_datetime.py

示例10: test_pickling_subclass

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_pickling_subclass(self):
        # Make sure we can pickle/unpickle an instance of a subclass.
        offset = timedelta(minutes=-300)
        orig = PicklableFixedOffset(offset, 'cookie')
        self.assertIsInstance(orig, tzinfo)
        self.assertTrue(type(orig) is PicklableFixedOffset)
        self.assertEqual(orig.utcoffset(None), offset)
        self.assertEqual(orig.tzname(None), 'cookie')
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIsInstance(derived, tzinfo)
            self.assertTrue(type(derived) is PicklableFixedOffset)
            self.assertEqual(derived.utcoffset(None), offset)
            self.assertEqual(derived.tzname(None), 'cookie')

#############################################################################
# Base clase for testing a particular aspect of timedelta, time, date and
# datetime comparisons. 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_datetime.py

示例11: _interval_unpack

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def _interval_unpack(time_bytes):
    """
    :rtype: time
    """
    try:
        return time(*unpack(">3b", time_bytes))
    except Exception:
        return None 
开发者ID:civic,项目名称:elitech-datareader,代码行数:10,代码来源:msg.py

示例12: _interval_pack

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def _interval_pack(t):
    """
    :param t: time.time
    :return: bytes
    """
    return _intarray2bytes([t.hour, t.minute, t.second]) 
开发者ID:civic,项目名称:elitech-datareader,代码行数:8,代码来源:msg.py

示例13: to_bytes

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def to_bytes(self):
        write_bytes = pack(
            ">b"  # 0x33
            "B"  # target station no
            "2s"  # 0x0700
            "7s",  # set time
            0x33,
            self.target_station_no,
            _bin('07 00'),
            _datetime_pack(self.set_time),
            )

        ba = _append_checksum(write_bytes)
        return ba 
开发者ID:civic,项目名称:elitech-datareader,代码行数:16,代码来源:msg.py

示例14: test_fromtimestamp

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_fromtimestamp(self):
        import time

        # Try an arbitrary fixed value.
        year, month, day = 1999, 9, 19
        ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1))
        d = self.theclass.fromtimestamp(ts)
        self.assertEqual(d.year, year)
        self.assertEqual(d.month, month)
        self.assertEqual(d.day, day) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_datetime.py

示例15: test_today

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import time [as 别名]
def test_today(self):
        import time

        # We claim that today() is like fromtimestamp(time.time()), so
        # prove it.
        for dummy in range(3):
            today = self.theclass.today()
            ts = time.time()
            todayagain = self.theclass.fromtimestamp(ts)
            if today == todayagain:
                break
            # There are several legit reasons that could fail:
            # 1. It recently became midnight, between the today() and the
            #    time() calls.
            # 2. The platform time() has such fine resolution that we'll
            #    never get the same value twice.
            # 3. The platform time() has poor resolution, and we just
            #    happened to call today() right before a resolution quantum
            #    boundary.
            # 4. The system clock got fiddled between calls.
            # In any case, wait a little while and try again.
            time.sleep(0.1)

        # It worked or it didn't.  If it didn't, assume it's reason #2, and
        # let the test pass if they're within half a second of each other.
        if today != todayagain:
            self.assertAlmostEqual(todayagain, today,
                                   delta=timedelta(seconds=0.5)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:test_datetime.py


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