How to use the pendulum.date 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 / date / test_sub.py View on Github external
def test_subtract_months_positive():
    assert pendulum.date(1975, 1, 1).subtract(months=1).month == 12
github sdispater / pendulum / tests / date / test_day_of_week_modifiers.py View on Github external
def test_next_invalid():
    dt = pendulum.date(1975, 5, 21)

    with pytest.raises(ValueError):
        dt.next(7)
github sdispater / pendulum / tests / date / test_start_end_of.py View on Github external
def test_average_from_lower():
    d1 = pendulum.date(2009, 12, 31)
    d2 = pendulum.date(2000, 1, 1).average(d1)
    assert_date(d2, 2004, 12, 31)
github sdispater / pendulum / tests / date / test_day_of_week_modifiers.py View on Github external
def test_previous_monday():
    d = pendulum.date(1975, 5, 21).previous(pendulum.MONDAY)
    assert_date(d, 1975, 5, 19)
github sdispater / pendulum / tests / date / test_day_of_week_modifiers.py View on Github external
def test_end_of_week_from_week_end():
    d = pendulum.date(1980, 8, 10).end_of("week")
    assert_date(d, 1980, 8, 10)
github sdispater / pendulum / tests / date / test_add.py View on Github external
def test_add_years_positive():
    assert pendulum.date(1975, 1, 1).add(years=1).year == 1976
github sdispater / pendulum / tests / date / test_day_of_week_modifiers.py View on Github external
def test_first_friday_of_quarter():
    d = pendulum.date(1975, 11, 21).first_of("quarter", 5)
    assert_date(d, 1975, 10, 3)
github sdispater / pendulum / tests / date / test_day_of_week_modifiers.py View on Github external
def test_2rd_wednesday_of_year():
    d = pendulum.date(1975, 8, 5).nth_of("year", 3, pendulum.WEDNESDAY)
    assert_date(d, 1975, 1, 15)
github Flowminder / FlowKit / autoflow / autoflow / date_stencil.py View on Github external
Date to calculate the offset relative to.

        Returns
        -------
        pendulum.Date
            reference_date + offset (if offset is an integer), or offset (if offset is a date).
        
        Raises
        ------
        TypeError
            If type(offset) is not either int or datetime.date
        """
        if isinstance(offset, datetime.date):
            date_from_offset = pendulum.date(offset.year, offset.month, offset.day)
        elif isinstance(offset, int):
            date_from_offset = pendulum.date(
                reference_date.year, reference_date.month, reference_date.day
            ).add(days=offset)
        else:
            raise TypeError(
                f"Invalid type for offset: expected 'date' or 'int', not '{type(offset).__name__}'."
            )
        return date_from_offset
github sdispater / pendulum / pendulum / parser.py View on Github external
parsed = base_parse(text, **options)

    if isinstance(parsed, datetime.datetime):
        return pendulum.datetime(
            parsed.year,
            parsed.month,
            parsed.day,
            parsed.hour,
            parsed.minute,
            parsed.second,
            parsed.microsecond,
            tz=parsed.tzinfo or options.get("tz", UTC),
        )

    if isinstance(parsed, datetime.date):
        return pendulum.date(parsed.year, parsed.month, parsed.day)

    if isinstance(parsed, datetime.time):
        return pendulum.time(
            parsed.hour, parsed.minute, parsed.second, parsed.microsecond
        )

    if isinstance(parsed, _Interval):
        if parsed.duration is not None:
            duration = parsed.duration

            if parsed.start is not None:
                dt = pendulum.instance(parsed.start, tz=options.get("tz", UTC))

                return pendulum.period(
                    dt,
                    dt.add(