How to use the pendulum.DateTime function in pendulum

To help you get started, we’ve selected a few pendulum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdispater / pendulum / tests / datetime / test_getters.py View on Github external
def test_is_past():
    with pendulum.test(DateTime(2000, 1, 1)):
        d = pendulum.now()
        assert not d.is_past()
        d = d.subtract(days=1)
        assert d.is_past()
github sdispater / pendulum / tests / time_tests / test_testing_aids.py View on Github external
def test_set_test_now_pendulum_instance(self):
        test_now = DateTime(2000, 11, 10, 12, 34, 56, 123456)

        Time.set_test_now(test_now)

        self.assertTime(Time.now(), 12, 34, 56, 123456)
github sdispater / pendulum / tests / period / test_construct.py View on Github external
def test_accuracy():
    dt1 = pendulum.DateTime(2000, 11, 20)
    dt2 = pendulum.DateTime(2000, 11, 25)
    dt3 = pendulum.DateTime(2016, 11, 5)
    p1 = pendulum.period(dt1, dt3)
    p2 = pendulum.period(dt2, dt3)

    assert p1.years == 15
    assert p1.in_years() == 15
    assert p1.months == 11
    assert p1.in_months() == 191
    assert p1.days == 5829
    assert p1.remaining_days == 2
    assert p1.in_days() == 5829

    assert p2.years == 15
    assert p2.in_years() == 15
    assert p2.months == 11
github sdispater / pendulum / tests / period / test_construct.py View on Github external
def test_with_pendulum():
    dt1 = pendulum.DateTime(2000, 1, 1)
    dt2 = pendulum.DateTime(2000, 1, 31)
    p = pendulum.period(dt1, dt2)

    assert_datetime(p.start, 2000, 1, 1)
    assert_datetime(p.end, 2000, 1, 31)
github emmett-framework / emmett / weppy / expose.py View on Github external
def _parse_date_reqarg_opt(args, route_args):
        try:
            for arg in args:
                if route_args[arg] is None:
                    continue
                route_args[arg] = pendulum.DateTime.strptime(
                    route_args[arg], "%Y-%m-%d")
        except Exception:
            raise HTTP(404)
github emmett-framework / emmett / weppy / _internal.py View on Github external
def _pendulum_to_naive_datetime(obj):
    obj = obj.in_timezone('UTC')
    return datetime.datetime(
        obj.year, obj.month, obj.day,
        obj.hour, obj.minute, obj.second, obj.microsecond
    )


# datetime.date = Date
# datetime.time = Time
# datetime.datetime = DateTime
# pendulum.DateTime.__json__ = _pendulum_to_json
pendulum.DateTime.as_datetime = _pendulum_to_datetime
pendulum.DateTime.as_naive_datetime = _pendulum_to_naive_datetime
github andrewcooke / choochoo / py / ch2 / lib / date.py View on Github external
def local_date_to_time(date, none=False):
    if none and date is None: return None
    date = to_date(date)
    ptime = p.DateTime(year=date.year, month=date.month, day=date.day,
                       tzinfo=p.tz.get_local_timezone()).in_timezone(dt.timezone.utc)
    return dt.datetime(*ptime.timetuple()[:6], tzinfo=dt.timezone.utc)
github emmett-framework / emmett / weppy / _internal.py View on Github external
)


def _pendulum_to_naive_datetime(obj):
    obj = obj.in_timezone('UTC')
    return datetime.datetime(
        obj.year, obj.month, obj.day,
        obj.hour, obj.minute, obj.second, obj.microsecond
    )


# datetime.date = Date
# datetime.time = Time
# datetime.datetime = DateTime
# pendulum.DateTime.__json__ = _pendulum_to_json
pendulum.DateTime.as_datetime = _pendulum_to_datetime
pendulum.DateTime.as_naive_datetime = _pendulum_to_naive_datetime
github sdispater / pendulum / pendulum / period.py View on Github external
)
            else:
                _start = datetime(
                    start.year,
                    start.month,
                    start.day,
                    start.hour,
                    start.minute,
                    start.second,
                    start.microsecond,
                    tzinfo=start.tzinfo,
                )
        elif isinstance(start, pendulum.Date):
            _start = date(start.year, start.month, start.day)

        if isinstance(end, pendulum.DateTime):
            if _HAS_FOLD:
                _end = datetime(
                    end.year,
                    end.month,
                    end.day,
                    end.hour,
                    end.minute,
                    end.second,
                    end.microsecond,
                    tzinfo=end.tzinfo,
                    fold=end.fold,
                )
            else:
                _end = datetime(
                    end.year,
                    end.month,