Skip to main content

approxidate

approxidate is a quick way to get a unix timestamp from a ton of arbitrary date formats. It consists of one function:

DateType = typing.Union[
    datetime.date,
    datetime.datetime,
    datetime.time,
    float,
    None,
]

def approx(date: str, *, relative_to: DateType = None) -> float:
    """
    Get a unix timestamp from an arbitrary date string.

    If `relative_to` is None, and the given date string is missing date or time,
    now will be used. Otherwise, the missing units will be filled in from the
    date/time represented by relative_to.

    If `relative_to` is a float, it's treated as a unix timestamp.
    """

Example usage:

import datetime

import approxidate

approxidate.approx("10/10/2013 10:10:10.312 +0500")
approxidate.approx("10/March/2013 10:10:10.312 +0500")
approxidate.approx("10/Mar/2013 10:10:10.312 +0500")
approxidate.approx("2013 march 10 04:00:07")
approxidate.approx("2013 10 march 04:00:07")

# Parsed relative to now
approxidate.approx("00:00:07.657891")
approxidate.approx("mar 10")
approxidate.approx("10 mar 2013")
approxidate.approx("march 10 2013")

rel = datetime.datetime.now() + datetime.timedelta(hours=-1)
approxidate.approx("00:00:07.657891", relative_to=rel)

rel = datetime.date.today()
approxidate.approx("00:00:07.657891", relative_to=rel)

# Relative to a unix timestamp
approxidate.approx("mar 10", relative_to=1579733041)

Metadata

Release files for approxidate 1.0.4

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

Source distribution (sdist)

Source distribution for approxidate 1.0.4
File Size Uploaded Provenance
approxidate-1.0.4.tar.gz 9.6 kB Without provenance Details

Release files / approxidate-1.0.4.tar.gz

Download URL approxidate-1.0.4.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e140f4150432ca79a5c866606059171724faa45eedc5e5a4881d01aa0b11b48d
BLAKE2b-256 checksum
How to use checksums
937a85a6caccb9d429abcfb526bfbc1d6f7bcc5d24788efc6ad530723b9bd642
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

Security for approxidate 1.0.4

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.

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