Skip to main content

Latest Version Python Versions Build Status

Plummet

Methods for testing with pendulum timestamps.

The most useful method for testing is the frozen_time() method which allows you to fix a moment in time so that all calls to pendulum.now() return the provided timestamp.

It is also possible to freeze timestamps given by datetime.now() by installing the time-machine extra dependency.

Methods

Here is a breakdown of the methods provided, what they do, and examples of how to use them

momentize()

This method is used to turn a variety of different timestamps into pendulum.DateTime instances in the UTC timezone.

Accepted types

  • String timestamps (anything that pendulum can parse)
  • datetime.datetime instances
  • pendulum.DateTime instances (that might be in other timezones)
  • None -- returns the current moment in UTC

Examples

Get the current time in UTC:

>>> momentize()
DateTime(2021, 11, 17, 21, 15, 0, 20728, tzinfo=Timezone('UTC'))

Convert a string timestamp:

>>> momentize("2021-11-17 21:29:00")
DateTime(2021, 11, 17, 21, 29, 0, tzinfo=Timezone('UTC'))

See pendulum's documentation for more info.

Convert a datetime.datetime:

>>> momentize(datetime.datetime(2021, 11, 17, 21, 29, 0))
DateTime(2021, 11, 17, 21, 29, 0, tzinfo=Timezone('UTC'))

If momentize cannot convert the provided object, it will raise an exception.

moments_match()

This method is used to compare two possibly different forms of timestamps to make sure they are exactly equal. Under the hood, it is using momentize() to convert the arguments to pendulum.DateTime instances and then compares the two.

Accepted types

  • String timestamps (anything that pendulum can parse)
  • datetime.datetime instances
  • pendulum.DateTime instances (that might be in other timezones)
  • None -- compares the current moment in UTC

Examples

Compare a string to a datetime.datetime:

>>> moments_match("2021-11-17 21:41:00", datetime.datetime(2021, 11, 17, 21, 41, 0))
True

Compare a pendulum.DateTime to a datetime.datetime in different timezones:

>>> moments_match(
...     pendulum.datetime(
...         2021, 11, 17, 13, 44, 0,
...         tz="America/Los_Angeles",
...         ),
...     datetime.datetime(
...         2021, 11, 17, 16, 44, 0,
...         tzinfo=datetime.timezone(datetime.timedelta(hours=-4)),
...     ),
... )
...
True

frozen_time()

The frozen_time method is the main functionality of this package. It allows you to freeze the time returned by pendulum.now() (and it's relatives) to a given moment.

Accepted types

  • String timestamps (anything that pendulum can parse)
  • datetime.datetime instances
  • pendulum.DateTime instances (that might be in other timezones)
  • None -- freeze at the current moment in UTC

Examples

Freeze time at a specific moment:

>>> with frozen_time("2021-11-17 22:03:00"):
...     now = pendulum.now("UTC")
...     print(now)
...
2021-11-17T22:03:00+00:00

Freezing datetime.now()

By default, the frozen_time method only works for pendulum.now(). However, if you install with the extra "time-machine", it is possible to make frozen_time work with datetime.now() as well.

Installing the extra "time-machine" dependency

To install the extra dependency with pip:

$ pip install plummet[time-machine]

To install the extra dependency with poetry:

$ poetry add plummet[time-machine]

Now, plummet will freeze datetime.now() as well:

>>> with frozen_time("2021-11-17 22:03:00"):
...     pendulum_now = pendulum.now("UTC")
...     datetime_now = datetime.now(tz=timezone.utc)
...     print(pendulum_now)
...     print(datetime_now)
...
2021-11-17T22:03:00+00:00
2021-11-17 22:03:00+00:00

Testing

To run the testing suite:

$ make test

To run the full set of quality checks:

$ make qa

Metadata

Release files for plummet 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plummet 2.0.0
File Size Uploaded Provenance Actions
plummet-2.0.0.tar.gz 4.4 kB Without provenance Details for plummet-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plummet 2.0.0
File Interpreter ABI Platform Actions
plummet-2.0.0-py3-none-any.whl Python 3 none any Details for plummet-2.0.0-py3-none-any.whl

Total release size: 8.9 kB

Release files / plummet-2.0.0.tar.gz

Download URL plummet-2.0.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5b9924659e8c838d30535e53bb90c3670d14528f297bd1abd213ee60e07d465c
BLAKE2b-256 checksum
How to use checksums
096d66413f2c4bdf7d7828c2e13686d7513a2d1072e40e9e542ea00c126ee656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / plummet-2.0.0-py3-none-any.whl

Download URL plummet-2.0.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0710bd05e1674e6761ba5d30a2e431865a72389af42abacffe38f6bcb40277e4
BLAKE2b-256 checksum
How to use checksums
c7121f657252973b06f6e1bb3196778b932ab1dccb18270dac2fe04e0df7be6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for plummet 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page