How to use the pendulum.Pendulum 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 / formatting_tests / test_classic_formatter.py View on Github external
def test_day_of_week(self):
        f = ClassicFormatter()
        d = Pendulum(2016, 8, 28)

        self.assertEqual('Sun', f.format(d, '%a'))
        self.assertEqual('Sunday', f.format(d, '%A'))

        self.assertEqual('dim', f.format(d, '%a', locale='fr'))
        self.assertEqual('dimanche', f.format(d, '%A', locale='fr'))
github sdispater / pendulum / tests / pendulum_tests / test_start_end_of.py View on Github external
def test_start_of_year_from_first_day(self):
        d = Pendulum(2000, 1, 1, 1, 1, 1)
        new = d.start_of('year')
        self.assertPendulum(new, 2000, 1, 1, 0, 0, 0)
github sdispater / pendulum / tests / pendulum_tests / test_start_end_of.py View on Github external
def test_start_of_second(self):
        d = Pendulum.now()
        new = d.start_of('second')
        self.assertIsInstanceOfPendulum(new)
        self.assertPendulum(new, d.year, d.month, d.day, d.hour, d.minute, d.second, 0)
github sdispater / pendulum / tests / pendulum_tests / test_start_end_of.py View on Github external
def test_start_of_with_transition(self):
        d = Pendulum(2013, 10, 27, 23, 59, 59, tzinfo='Europe/Paris')
        self.assertEqual(3600, d.offset)
        self.assertEqual(7200, d.start_of('month').offset)
        self.assertEqual(7200, d.start_of('day').offset)
        self.assertEqual(3600, d.start_of('year').offset)
github sdispater / pendulum / tests / pendulum_tests / test_day_of_week_modifiers.py View on Github external
def test_end_of_week(self):
        d = Pendulum(1980, 8, 7, 12, 11, 9).end_of('week')
        self.assertPendulum(d, 1980, 8, 10, 23, 59, 59)
github stack-of-tasks / pinocchio / doc / d-practical-exercises / src / dpendulum.py View on Github external
def __init__(self):
        self.pendulum = Pendulum(1)
        self.pendulum.DT  = DT
        self.pendulum.NDT = 5
github Flowminder / FlowKit / flowetl / etl / etl / production_task_callables.py View on Github external
session, source_table, event_time_col="event_time"
            )
            unprocessed_dates = [
                date
                for date in dates_present
                if ETLRecord.can_process(
                    cdr_type=cdr_type, cdr_date=date, session=session
                )
            ]
            logger.info(f"Dates found: {dates_present}")
            logger.info(f"Unprocessed dates: {unprocessed_dates}")

            for cdr_date in unprocessed_dates:
                uuid = uuid1()
                cdr_date_str = cdr_date.strftime("%Y%m%d")
                execution_date = pendulum.Pendulum(
                    cdr_date.year, cdr_date.month, cdr_date.day
                )
                config = {
                    "cdr_type": cdr_type,
                    "cdr_date": cdr_date,
                    "source_table": source_table,
                }
                trigger_dag(
                    f"etl_{cdr_type}",
                    execution_date=execution_date,
                    run_id=f"{cdr_type.upper()}_{cdr_date_str}-{str(uuid)}",
                    conf=config,
                    replace_microseconds=False,
                )
        else:
            raise ValueError(f"Invalid source type: '{source_type}'")
github CenterForOpenScience / SHARE / share / harvest / base.py View on Github external
"""
        if not isinstance(start, datetime.date):
            raise TypeError('start must be a datetime.date. Got {!r}'.format(start))

        if not isinstance(end, datetime.date):
            raise TypeError('end must be a datetime.date. Got {!r}'.format(end))

        if start >= end:
            raise ValueError('start must be before end. {!r} > {!r}'.format(start, end))

        if limit == 0:
            return  # No need to do anything

        # Cast to datetimes for compat reasons
        start = pendulum.Pendulum.instance(datetime.datetime.combine(start, datetime.time(0, 0, 0, 0, timezone.utc)))
        end = pendulum.Pendulum.instance(datetime.datetime.combine(end, datetime.time(0, 0, 0, 0, timezone.utc)))

        if hasattr(self, 'shift_range'):
            warnings.warn(
                '{!r} implements a deprecated interface. '
                'Handle date transforms in _do_fetch. '
                'shift_range will no longer be called in SHARE 2.9.0'.format(self),
                DeprecationWarning
            )
            start, end = self.shift_range(start, end)

        data_gen = self._do_fetch(start, end, **self._get_kwargs(**kwargs))

        if not isinstance(data_gen, types.GeneratorType) and len(data_gen) != 0:
            raise TypeError('{!r}._do_fetch must return a GeneratorType for optimal performance and memory usage'.format(self))
github CenterForOpenScience / SHARE / share / harvest / harvester.py View on Github external
def _validate_dates(self, start_date, end_date):
        assert not (bool(start_date) ^ bool(end_date)), 'Must specify both a start and end date or neither'
        assert isinstance(start_date, (datetime.timedelta, datetime.datetime, pendulum.Pendulum)) and isinstance(end_date, (datetime.timedelta, datetime.datetime, pendulum.Pendulum)), 'start_date and end_date must be either datetimes or timedeltas'
        assert not (isinstance(start_date, datetime.timedelta) and isinstance(end_date, datetime.timedelta)), 'Only one of start_date and end_date may be a timedelta'

        if isinstance(start_date, datetime.datetime):
            start_date = pendulum.instance(start_date)

        if isinstance(end_date, datetime.datetime):
            end_date = pendulum.instance(end_date)

        if isinstance(start_date, datetime.timedelta):
            start_date = pendulum.instance(end_date + start_date)

        if isinstance(end_date, datetime.timedelta):
            end_date = pendulum.instance(start_date + end_date)

        og_start, og_end = start_date, end_date
        start_date, end_date = self.shift_range(start_date, end_date)
github CenterForOpenScience / SHARE / share / harvest / base.py View on Github external
"""
        if not isinstance(start, datetime.date):
            raise TypeError('start must be a datetime.date. Got {!r}'.format(start))

        if not isinstance(end, datetime.date):
            raise TypeError('end must be a datetime.date. Got {!r}'.format(end))

        if start >= end:
            raise ValueError('start must be before end. {!r} > {!r}'.format(start, end))

        if limit == 0:
            return  # No need to do anything

        # Cast to datetimes for compat reasons
        start = pendulum.Pendulum.instance(datetime.datetime.combine(start, datetime.time(0, 0, 0, 0, timezone.utc)))
        end = pendulum.Pendulum.instance(datetime.datetime.combine(end, datetime.time(0, 0, 0, 0, timezone.utc)))

        if hasattr(self, 'shift_range'):
            warnings.warn(
                '{!r} implements a deprecated interface. '
                'Handle date transforms in _do_fetch. '
                'shift_range will no longer be called in SHARE 2.9.0'.format(self),
                DeprecationWarning
            )
            start, end = self.shift_range(start, end)

        data_gen = self._do_fetch(start, end, **self._get_kwargs(**kwargs))

        if not isinstance(data_gen, types.GeneratorType) and len(data_gen) != 0:
            raise TypeError('{!r}._do_fetch must return a GeneratorType for optimal performance and memory usage'.format(self))

        for i, blob in enumerate(data_gen):