Skip to main content

Add your description here

Project description

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'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

str2td-0.0.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

str2td-0.0.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file str2td-0.0.2.tar.gz.

File metadata

  • Download URL: str2td-0.0.2.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for str2td-0.0.2.tar.gz
Algorithm Hash digest
SHA256 19f98c0ecdc8c215655aada38e3c62f45b3a2e9fb973321de7f80a4e1e8b189b
MD5 ed32a661f43ca5f25c795f5c807c2ad9
BLAKE2b-256 9210cc583a215a0e855c57cf705eeaf78ab092616a25c85a570ffa708e58567d

See more details on using hashes here.

File details

Details for the file str2td-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: str2td-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for str2td-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7616de9a05fe2fd0f6c36fa8350c127bcb698aedaf5ad6f48a4a99966c7d6540
MD5 429849628583ff6f88143e82f43a825f
BLAKE2b-256 b4012067557140a8bddb6321a7cb3ece147baa2f0749495a62ec677d42bbac9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page