當前位置: 首頁>>代碼示例>>Python>>正文


Python timedelta.max方法代碼示例

本文整理匯總了Python中datetime.timedelta.max方法的典型用法代碼示例。如果您正苦於以下問題:Python timedelta.max方法的具體用法?Python timedelta.max怎麽用?Python timedelta.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datetime.timedelta的用法示例。


在下文中一共展示了timedelta.max方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_extreme_ordinals

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [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

示例2: format_ad_timedelta

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def format_ad_timedelta(raw_value):
    """
    Convert a negative filetime value to a timedelta.
    """
    # Active Directory stores attributes like "minPwdAge" as a negative
    # "filetime" timestamp, which is the number of 100-nanosecond intervals that
    # have elapsed since the 0 hour on January 1, 1601.
    #
    # Handle the minimum value that can be stored in a 64 bit signed integer.
    # See https://docs.microsoft.com/en-us/dotnet/api/system.int64.minvalue
    # In attributes like "maxPwdAge", this signifies never.
    if raw_value == b'-9223372036854775808':
        return timedelta.max
    # We can reuse format_ad_timestamp to get a datetime object from the
    # timestamp. Afterwards, we can subtract a datetime representing 0 hour on
    # January 1, 1601 from the returned datetime to get the timedelta.
    return format_ad_timestamp(raw_value) - format_ad_timestamp(0) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:19,代碼來源:formatters.py

示例3: test_max_runs_when_no_files

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_max_runs_when_no_files(self):

        child_pipe, parent_pipe = multiprocessing.Pipe()

        with TemporaryDirectory(prefix="empty-airflow-dags-") as dags_folder:
            async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')
            manager = DagFileProcessorManager(
                dag_directory=dags_folder,
                max_runs=1,
                processor_factory=FakeDagFileProcessorRunner._fake_dag_processor_factory,
                processor_timeout=timedelta.max,
                signal_conn=child_pipe,
                dag_ids=[],
                pickle_dags=False,
                async_mode=async_mode)

            self.run_processor_manager_one_loop(manager, parent_pipe)
        child_pipe.close()
        parent_pipe.close() 
開發者ID:apache,項目名稱:airflow,代碼行數:21,代碼來源:test_dag_processing.py

示例4: test_set_file_paths_when_processor_file_path_not_in_new_file_paths

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_set_file_paths_when_processor_file_path_not_in_new_file_paths(self):
        manager = DagFileProcessorManager(
            dag_directory='directory',
            max_runs=1,
            processor_factory=MagicMock().return_value,
            processor_timeout=timedelta.max,
            signal_conn=MagicMock(),
            dag_ids=[],
            pickle_dags=False,
            async_mode=True)

        mock_processor = MagicMock()
        mock_processor.stop.side_effect = AttributeError(
            'DagFileProcessor object has no attribute stop')
        mock_processor.terminate.side_effect = None

        manager._processors['missing_file.txt'] = mock_processor
        manager._file_stats['missing_file.txt'] = DagFileStat(0, 0, None, None, 0)

        manager.set_file_paths(['abc.txt'])
        self.assertDictEqual(manager._processors, {}) 
開發者ID:apache,項目名稱:airflow,代碼行數:23,代碼來源:test_dag_processing.py

示例5: test_set_file_paths_when_processor_file_path_is_in_new_file_paths

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_set_file_paths_when_processor_file_path_is_in_new_file_paths(self):
        manager = DagFileProcessorManager(
            dag_directory='directory',
            max_runs=1,
            processor_factory=MagicMock().return_value,
            processor_timeout=timedelta.max,
            signal_conn=MagicMock(),
            dag_ids=[],
            pickle_dags=False,
            async_mode=True)

        mock_processor = MagicMock()
        mock_processor.stop.side_effect = AttributeError(
            'DagFileProcessor object has no attribute stop')
        mock_processor.terminate.side_effect = None

        manager._processors['abc.txt'] = mock_processor

        manager.set_file_paths(['abc.txt'])
        self.assertDictEqual(manager._processors, {'abc.txt': mock_processor}) 
開發者ID:apache,項目名稱:airflow,代碼行數:22,代碼來源:test_dag_processing.py

示例6: test_parse_once

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_parse_once(self):
        test_dag_path = os.path.join(TEST_DAG_FOLDER, 'test_scheduler_dags.py')
        async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')
        processor_agent = DagFileProcessorAgent(test_dag_path,
                                                1,
                                                type(self)._processor_factory,
                                                timedelta.max,
                                                [],
                                                False,
                                                async_mode)
        processor_agent.start()
        parsing_result = []
        if not async_mode:
            processor_agent.run_single_parsing_loop()
        while not processor_agent.done:
            if not async_mode:
                processor_agent.wait_until_finished()
            parsing_result.extend(processor_agent.harvest_simple_dags())

        dag_ids = [result.dag_id for result in parsing_result]
        self.assertEqual(dag_ids.count('test_start_date_scheduling'), 1) 
開發者ID:apache,項目名稱:airflow,代碼行數:23,代碼來源:test_dag_processing.py

示例7: test_launch_process

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_launch_process(self):
        test_dag_path = os.path.join(TEST_DAG_FOLDER, 'test_scheduler_dags.py')
        async_mode = 'sqlite' not in conf.get('core', 'sql_alchemy_conn')

        log_file_loc = conf.get('logging', 'DAG_PROCESSOR_MANAGER_LOG_LOCATION')
        try:
            os.remove(log_file_loc)
        except OSError:
            pass

        # Starting dag processing with 0 max_runs to avoid redundant operations.
        processor_agent = DagFileProcessorAgent(test_dag_path,
                                                0,
                                                type(self)._processor_factory,
                                                timedelta.max,
                                                [],
                                                False,
                                                async_mode)
        processor_agent.start()
        if not async_mode:
            processor_agent.run_single_parsing_loop()

        processor_agent._process.join()

        self.assertTrue(os.path.isfile(log_file_loc)) 
開發者ID:apache,項目名稱:airflow,代碼行數:27,代碼來源:test_dag_processing.py

示例8: do_pull_minutes_active

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def do_pull_minutes_active(property: str, start_time: datetime, end_time: datetime,
                           realm: Optional[Realm] = None) -> int:
    user_activity_intervals = UserActivityInterval.objects.filter(
        end__gt=start_time, start__lt=end_time,
    ).select_related(
        'user_profile',
    ).values_list(
        'user_profile_id', 'user_profile__realm_id', 'start', 'end')

    seconds_active: Dict[Tuple[int, int], float] = defaultdict(float)
    for user_id, realm_id, interval_start, interval_end in user_activity_intervals:
        if realm is None or realm.id == realm_id:
            start = max(start_time, interval_start)
            end = min(end_time, interval_end)
            seconds_active[(user_id, realm_id)] += (end - start).total_seconds()

    rows = [UserCount(user_id=ids[0], realm_id=ids[1], property=property,
                      end_time=end_time, value=int(seconds // 60))
            for ids, seconds in seconds_active.items() if seconds >= 60]
    UserCount.objects.bulk_create(rows)
    return len(rows) 
開發者ID:zulip,項目名稱:zulip,代碼行數:23,代碼來源:counts.py

示例9: test_overflow

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_overflow(self):
        tiny = timedelta.resolution

        td = timedelta.min + tiny
        td -= tiny  # no problem
        self.assertRaises(OverflowError, td.__sub__, tiny)
        self.assertRaises(OverflowError, td.__add__, -tiny)

        td = timedelta.max - tiny
        td += tiny  # no problem
        self.assertRaises(OverflowError, td.__add__, tiny)
        self.assertRaises(OverflowError, td.__sub__, -tiny)

        self.assertRaises(OverflowError, lambda: -timedelta.max)

        day = timedelta(1)
        self.assertRaises(OverflowError, day.__mul__, 10**9)
        self.assertRaises(OverflowError, day.__mul__, 1e9)
        self.assertRaises(OverflowError, day.__truediv__, 1e-20)
        self.assertRaises(OverflowError, day.__truediv__, 1e-10)
        self.assertRaises(OverflowError, day.__truediv__, 9e-10) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:23,代碼來源:datetimetester.py

示例10: test_non_abstractness

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_non_abstractness(self):
        # In order to allow subclasses to get pickled, the C implementation
        # wasn't able to get away with having __init__ raise
        # NotImplementedError.
        useless = tzinfo()
        dt = datetime.max
        self.assertRaises(NotImplementedError, useless.tzname, dt)
        self.assertRaises(NotImplementedError, useless.utcoffset, dt)
        self.assertRaises(NotImplementedError, useless.dst, dt) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_datetime.py

示例11: test_resolution_info

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_resolution_info(self):
        self.assertIsInstance(timedelta.min, timedelta)
        self.assertIsInstance(timedelta.max, timedelta)
        self.assertIsInstance(timedelta.resolution, timedelta)
        self.assertTrue(timedelta.max > timedelta.min)
        self.assertEqual(timedelta.min, timedelta(-999999999))
        self.assertEqual(timedelta.max, timedelta(999999999, 24*3600-1, 1e6-1))
        self.assertEqual(timedelta.resolution, timedelta(0, 0, 1)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_datetime.py

示例12: test_overflow

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_overflow(self):
        tiny = timedelta.resolution

        td = timedelta.min + tiny
        td -= tiny  # no problem
        self.assertRaises(OverflowError, td.__sub__, tiny)
        self.assertRaises(OverflowError, td.__add__, -tiny)

        td = timedelta.max - tiny
        td += tiny  # no problem
        self.assertRaises(OverflowError, td.__add__, tiny)
        self.assertRaises(OverflowError, td.__sub__, -tiny)

        self.assertRaises(OverflowError, lambda: -timedelta.max) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_datetime.py

示例13: test_extreme_timedelta

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_extreme_timedelta(self):
        big = self.theclass.max - self.theclass.min
        # 3652058 days, 23 hours, 59 minutes, 59 seconds, 999999 microseconds
        n = (big.days*24*3600 + big.seconds)*1000000 + big.microseconds
        # n == 315537897599999999 ~= 2**58.13
        justasbig = timedelta(0, 0, n)
        self.assertEqual(big, justasbig)
        self.assertEqual(self.theclass.min + big, self.theclass.max)
        self.assertEqual(self.theclass.max - big, self.theclass.min) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_datetime.py

示例14: test_bool

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def test_bool(self):
        # All dates are considered true.
        self.assertTrue(self.theclass.min)
        self.assertTrue(self.theclass.max) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_datetime.py

示例15: valid_date_stop

# 需要導入模塊: from datetime import timedelta [as 別名]
# 或者: from datetime.timedelta import max [as 別名]
def valid_date_stop(date_stop):
    """ checks, whether date_stop has a valid value """
    if not date_stop:
        date_stop = Bank_Date.max
    return date_stop 
開發者ID:MartinPyka,項目名稱:financial_life,代碼行數:7,代碼來源:validate.py


注:本文中的datetime.timedelta.max方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。