Skip to main content

str2td

Easily express a timedelta in a succinct and human-readable way.

Usage example

from datetime import datetime
from lark import LarkError
from str2td import str2td

now = datetime.now().astimezone()
tz = now.tzinfo  # can be different if the string's timezone is different than your calculation timezone.

print(f"{now=:%Y-%m-%d %H:%M:%S (%Z)}\n")

try:
	string = input("Set a reminder in: ")
	td = str2td(string, now=now, tz=tz)
	print(f"Setting reminder at {now + td:%Y-%m-%d %H:%M:%S} ({td} from now).\n")

	string = input("When's your birthday? ")
	td = str2td(string, now=now, tz=tz)
	print(f"Great! Your nearest birthday is at: {now + td:%Y-%m-%d %H:%M:%S}, in {td.days} days.\n")

	string = input("[Seconds calculator]: ")
	td = str2td(string, now=now, tz=tz)
	print(f"{string} = {td.total_seconds()} seconds")
except LarkError as e:
	print("\nInvalid Syntax!")
	print("=" * 50)
	print(e)
	print("=" * 50)
Successful inputs
now=2025-05-13 21:01:41 (Central European Summer Time)

Set a reminder in: 3d!10:
Setting reminder at 2025-05-17 10:00:00 (3 days, 12:58:18.493712 from now).

When's your birthday? 10-10
Great! Your nearest birthday is at: 2025-10-10 21:01:41, in 150 days.

[Seconds calculator]: 3d-.25d5.5h1s
3d-.25d5.5h1s = 257401.0 seconds.
Erroring inputs
now=2025-05-13 21:12:22 (Central European Summer Time)

Set a reminder in: 1huj
Invalid Syntax!
Error trying to process rule "robostr_segment":

Unknown unit: 'huj'

Metadata

Release files for str2td 0.0.5

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

Source distribution (sdist)

Source distribution for str2td 0.0.5
File Size Uploaded Provenance Actions
str2td-0.0.5.tar.gz 15.3 kB Without provenance Details for str2td-0.0.5.tar.gz

Built distribution (wheel)

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

Total release size: 25.3 kB

Release files / str2td-0.0.5.tar.gz

Download URL str2td-0.0.5.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13461e9bf02647f092065fb1694e0b82fc3a81f705e5499357e65eaa186eee75
BLAKE2b-256 checksum
How to use checksums
24b010cd228ab34f837090e5dda31ac11ab295bd3502ec721915c2b7bf4ee963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release files / str2td-0.0.5-py3-none-any.whl

Download URL str2td-0.0.5-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07c964ab6f42ee2efbecb9bceaf00329adb1b70a9acce24c2ebbc713628853c7
BLAKE2b-256 checksum
How to use checksums
2e64aa7c361e5bf2ac407ab2dba6bc24bb5765b3cc229064c622c952a8d3d98f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Security for str2td 0.0.5

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