How to use pendulum - 10 common examples

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 edmunds / shadowreader / shadowreader / parser.py View on Github external
"""
    Print the results of the parse
    :param res: Results of the parsing
    :param tzinfo: Timezone found in logs
    :param app: Name of application for the logs
    """
    mins_of_data = len(res)
    total_reqs = sum([x["num_uris"] for x in res])
    max_reqs = max([x["num_uris"] for x in res])
    min_reqs = min([x["num_uris"] for x in res])
    avg_reqs = total_reqs // mins_of_data

    first, last = res[0], res[-1]
    first, last = first["timestamp"], last["timestamp"]
    first = pendulum.from_timestamp(first, tzinfo)
    last = pendulum.from_timestamp(last, tzinfo)
    first, last = first.isoformat()[:16], last.isoformat()[:16]

    test_params = {
        "base_url": "http://$your_base_url",
        "rate": 100,
        "replay_start_time": first,
        "replay_end_time": last,
        "identifier": "oss",
    }

    dump = json.dumps(test_params, indent=2)
    click.echo(f"{mins_of_data} minutes of traffic data was uploaded to S3.")
    click.echo(f"Average requests/min: {avg_reqs}")
    click.echo(f"Max requests/min: {max_reqs}")
    click.echo(f"Min requests/min: {min_reqs}")
    click.echo(f"Timezone found in logs: {tzinfo.name}")
github sdispater / pendulum / tests / datetime_tests / test_create_from_time.py View on Github external
def test_create_from_time_with_hour():
    with pendulum.test(pendulum.datetime(2016, 8, 11, 12, 34, 56, 123456)):
        d = pendulum.create(hour=23)
        assert d.hour == 23
        assert d.minute == 0
        assert d.second == 0
        assert d.microsecond == 0
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
def test_diff_for_humans_other_and_nearly_week():
    with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
        assert "6 days before" == pendulum.now().diff_for_humans(
            pendulum.now().add(days=6)
        )
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
def test_diff_for_humans_other_and_future_years():
    with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
        assert "2 years after" == pendulum.now().diff_for_humans(
            pendulum.now().subtract(years=2)
        )
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
def test_diff_for_humans_now_and_nearly_future_week():
    with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
        assert "in 6 days" == pendulum.now().add(days=6).diff_for_humans()
github DiscordWebsite / discord_logview / api / v2 / tests.py View on Github external
"bot": False,
                                  "discriminator": "4379",
                                  "username": "Big Nibba"
                              },
                              "content": "Idk",
                              "timestamp": "2019-12-22T02:40:01.531Z",
                              "edited_timestamp": None,
                              "attachments": [],
                              "embeds": [],
                              "mentions": []
                          }
                      ])
        payload = {
            'type': random.choice(list(all_types.keys())),
            'url': 'https://example.com/log',  # This URL is for testing purposes only
            'expires': pendulum.now().add(minutes=10).isoformat()
        }
        archive_response = self.client.post(reverse('v2:archive'), data=payload)
        self.assertEqual(archive_response.status_code, status.HTTP_201_CREATED)
        signed_data = archive_response.json()['url'].rsplit('/', 1)[1]

        # Test un-archiving
        accepts_headers = {**default_headers, 'ACCEPTS': 'application/json'}
        un_archive_response = self.client.get(reverse('v2:un-archive', kwargs={'signed_data': signed_data}),
                                              **accepts_headers)
        self.assertEqual(un_archive_response.status_code, status.HTTP_302_FOUND)
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
def test_diff_for_humans_other_and_nearly_future_hour():
    with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
        assert "59 minutes after" == pendulum.now().diff_for_humans(
            pendulum.now().subtract(minutes=59)
        )
github sdispater / pendulum / tests / localization / test_de.py View on Github external
def test_diff_for_humans():
    with pendulum.test(pendulum.datetime(2016, 8, 29)):
        diff_for_humans()
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
def test_diff_for_humans_other_and_months():
    with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
        assert "2 months before" == pendulum.now().diff_for_humans(
            pendulum.now().add(months=2)
        )
github sdispater / pendulum / tests / pendulum_tests / test_create_from_format.py View on Github external
def test_from_format(text, fmt, expected):
    with pendulum.test(pendulum.create(2015, 11, 12)):
        assert pendulum.from_format(text, fmt, formatter='alternative').isoformat() == expected