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


Python delorean.Delorean方法代码示例

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


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

示例1: test_hour

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_hour():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* 16 * * *', now)
        assert pycron.is_now('* */4 * * *', now)
        assert pycron.is_now('*/7 16 * * *', now)
        assert pycron.is_now('*/7 */8 * * *', now)
        assert pycron.is_now('* 2,8,16 * * *', now)
        assert pycron.is_now('* */9 * * *', now) is False
        assert pycron.is_now('* */5 * * *', now) is False
        assert pycron.is_now('*/3 */4 * * *', now) is False
        assert pycron.is_now('3 16 * * *', now) is False
        assert pycron.is_now('*/8 */3 * * *', now) is False
        assert pycron.is_now('* 2,8 * * *', now) is False
        assert pycron.is_now('* 16-20 * * *', now)
        assert pycron.is_now('* 0-10 * * *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:26,代码来源:test_hour.py

示例2: test_parser

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_parser():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* * * 6 *', now)
        assert pycron.is_now('* * * */2 *', now)
        assert pycron.is_now('* * * 1,4,6,12 *', now)
        assert pycron.is_now('* * * 5 *', now) is False
        assert pycron.is_now('* * * */5 *', now) is False
        assert pycron.is_now('* * * 1,4,12 *', now) is False
        assert pycron.MONTH_CHOICES[now.month - 1][1] == 'June'
        assert pycron.is_now('* * * 5-8 *', now)
        assert pycron.is_now('* * * 8-10 *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_month.py

示例3: test_minutes

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_minutes():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('0 * * * *', since, now) is False
        assert pycron.has_been('1 * * * *', since, now)
        assert pycron.has_been('2 * * * *', since, now)
        assert pycron.has_been('3 * * * *', since, now)
        assert pycron.has_been('4 * * * *', since, now) is False

    since = datetime(2015, 6, 18, 0, 1)
    now = datetime(2015, 6, 18, 0, 3)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例4: test_hours

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_hours():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('* 0 * * *', since, now) is False
        assert pycron.has_been('* 1 * * *', since, now)
        assert pycron.has_been('* 2 * * *', since, now)
        assert pycron.has_been('* 3 * * *', since, now)
        assert pycron.has_been('* 4 * * *', since, now) is False

    since = datetime(2015, 6, 18, 1, 0)
    now = datetime(2015, 6, 18, 3, 0)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例5: test_days

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_days():
    def run(since, now):
        assert pycron.has_been('* * * * *', since, now)
        assert pycron.has_been('* * 0 * *', since, now) is False
        assert pycron.has_been('* * 1 * *', since, now)
        assert pycron.has_been('* * 2 * *', since, now)
        assert pycron.has_been('* * 3 * *', since, now)
        assert pycron.has_been('* * 4 * *', since, now) is False

    since = datetime(2015, 6, 1, 0, 0)
    now = datetime(2015, 6, 3, 0, 0)
    run(since, now)
    run(since.replace(tzinfo=utc), now.replace(tzinfo=utc))
    run(pendulum.instance(since), pendulum.instance(now))
    run(arrow.get(since), arrow.get(now))
    run(udatetime.from_string(since.isoformat()), udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=since, timezone='UTC').datetime, Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:19,代码来源:test_has_been.py

示例6: test_minute_ranges

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_minute_ranges():
    for i in range(1, 59, 2):
        now = datetime(2015, 6, 18, 0, i)
        assert pycron.is_now('1-59/2 * * * *', now)
        assert pycron.is_now('1-59/2 * * * *', now.replace(tzinfo=utc))
        assert pycron.is_now('1-59/2 * * * *', pendulum.instance(now))
        assert pycron.is_now('1-59/2 * * * *', arrow.get(now))
        assert pycron.is_now('1-59/2 * * * *', udatetime.from_string(now.isoformat()))
        assert pycron.is_now('1-59/2 * * * *', Delorean(datetime=now, timezone='UTC').datetime)

    for i in range(0, 59, 2):
        now = datetime(2015, 6, 18, 0, i)
        assert pycron.is_now('1-59/2 * * * *', now) is False
        assert pycron.is_now('1-59/2 * * * *', now.replace(tzinfo=utc)) is False
        assert pycron.is_now('1-59/2 * * * *', pendulum.instance(now)) is False
        assert pycron.is_now('1-59/2 * * * *', arrow.get(now)) is False
        assert pycron.is_now('1-59/2 * * * *', udatetime.from_string(now.isoformat())) is False
        assert pycron.is_now('1-59/2 * * * *', Delorean(datetime=now, timezone='UTC').datetime) is False 
开发者ID:kipe,项目名称:pycron,代码行数:20,代码来源:test_minute.py

示例7: test_day_matching

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_day_matching():
    def run(now):
        for i in range(0, 7):
            # Test day matching from Sunday onwards...
            now += timedelta(days=1)
            assert pycron.is_now('* * * * %i' % (i), now)
            # Test weekdays
            assert pycron.is_now('* * * * 1,2,3,4,5', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * 1-5', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * 1,2,3,4-5', now) is (True if i not in [0, 6] else False)
            # Test weekends
            assert pycron.is_now('* * * * 0,6', now) is (True if i in [0, 6] else False)

    now = datetime(2015, 6, 20, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_dow.py

示例8: test_dom

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_dom():
    def run(now):
        assert pycron.is_now('* * * * *', now)
        assert pycron.is_now('* * 18 * *', now)
        assert pycron.is_now('* * */6 * *', now)
        assert pycron.is_now('* * 1,16,18 * *', now)
        assert pycron.is_now('* * 19 * *', now) is False
        assert pycron.is_now('* * */4 * *', now) is False
        assert pycron.is_now('* * 1,16 * *', now) is False
        assert pycron.is_now('* * 1,16 * *', now) is False
        assert pycron.is_now('* * 1-20 * *', now)
        assert pycron.is_now('* * 20-31 * *', now) is False

    now = datetime(2015, 6, 18, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:22,代码来源:test_dom.py

示例9: shift_epoch

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def shift_epoch(delorean, direction, unit, count):
    """ Gets the resulting epoch after a time shift of a Delorean
    
    Args:
        delorean: Delorean datetime instance to shift from.
        direction: String to shift time forwards or backwards.
            Valid values: 'last', 'next'.
        unit: String of time period unit for count argument.
            What unit in direction should be shifted?
            Valid values: 'hour', 'day', 'week', 'month', 'year'.
        count: Int of units.
            How many units to shift in direction?

    Returns:
        Int epoch in UTC from a shifted Delorean
    """
    return int(delorean._shift_date(direction, unit, count).epoch) 
开发者ID:amicks,项目名称:Speculator,代码行数:19,代码来源:date.py

示例10: generate_epochs

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def generate_epochs(delorean, direction, unit, count):
    """ Generates epochs from a shifted Delorean instance
    
    Args:
        delorean: Delorean datetime instance to shift from.
        direction: String to shift time forwards or backwards.
            Valid values: 'last', 'next'.
        unit: String of time period unit for count argument.
            What unit in direction should be shifted?
            Valid values: 'hour', 'day', 'week', 'month', 'year'.
        count: Int of units.
            How many units to shift in direction?

    Returns:
        Generator of count int epochs in UTC from a shifted Delorean
    """
    for shift in range(count):
        yield int(delorean._shift_date(direction, unit, shift).epoch) 
开发者ID:amicks,项目名称:Speculator,代码行数:20,代码来源:date.py

示例11: new_expiry

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def new_expiry(days=DEFAULT_PASTE_LIFETIME_DAYS):
    """Return an expiration `days` in the future"""
    now = delorean.Delorean()
    return now + datetime.timedelta(days=days) 
开发者ID:numberoverzero,项目名称:bloop,代码行数:6,代码来源:mixins.py

示例12: dynamo_load

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def dynamo_load(self, value, *, context, **kwargs):
        if value is None:
            return None
        dt = super().dynamo_load(value, context=context, **kwargs)
        return delorean.Delorean(dt).shift(self.timezone) 
开发者ID:numberoverzero,项目名称:bloop,代码行数:7,代码来源:delorean.py

示例13: test_datetime

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_datetime(timezone):
    delorean_now = delorean.Delorean(now)
    typedef = DateTime(timezone)

    assert typedef.dynamo_dump(delorean_now, context={}) == now_iso8601
    assert typedef.dynamo_load(now_iso8601, context={}).shift("utc").datetime == now 
开发者ID:numberoverzero,项目名称:bloop,代码行数:8,代码来源:test_delorean.py

示例14: test_timestamp

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_timestamp(timezone):
    delorean_now = delorean.Delorean(now)
    typedef = Timestamp(timezone)

    assert typedef.dynamo_dump(delorean_now, context={}) == now_timestamp
    assert typedef.dynamo_load(now_timestamp, context={}).shift("utc").datetime == now 
开发者ID:numberoverzero,项目名称:bloop,代码行数:8,代码来源:test_delorean.py

示例15: test_day_matching

# 需要导入模块: import delorean [as 别名]
# 或者: from delorean import Delorean [as 别名]
def test_day_matching():
    def run(now):
        for i in range(0, 7):
            # Test day matching from Sunday onwards...
            now += timedelta(days=1)
            assert pycron.is_now('* * * * %s' % (pycron.DAY_NAMES[i]), now)
            assert pycron.is_now('* * * * %s' % (pycron.DAY_ABBRS[i]), now)
            # Test weekdays
            assert pycron.is_now('* * * * mon,tue,wed,thu,fri',
                                 now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * monday,tuesday,wednesday,thursday,friday',
                                 now) is (True if i not in [0, 6] else False)
            assert pycron.is_now(
                '* * * * mon-fri', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now(
                '* * * * monday-friday', now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * mon,tue,wed,thu-fri',
                                 now) is (True if i not in [0, 6] else False)
            assert pycron.is_now('* * * * monday,tuesday,wednesday,thursday-friday',
                                 now) is (True if i not in [0, 6] else False)
            # Test weekends
            assert pycron.is_now(
                '* * * * sun,sat', now) is (True if i in [0, 6] else False)
            assert pycron.is_now(
                '* * * * sunday,saturday', now) is (True if i in [0, 6] else False)

    now = datetime(2015, 6, 20, 16, 7)
    run(now)
    run(now.replace(tzinfo=utc))
    run(pendulum.instance(now))
    run(arrow.get(now))
    run(udatetime.from_string(now.isoformat()))
    run(Delorean(datetime=now, timezone='UTC').datetime) 
开发者ID:kipe,项目名称:pycron,代码行数:35,代码来源:test_day_names.py


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