當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。