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.3.tar.gz
(13.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
str2td-0.0.3-py3-none-any.whl
(10.0 kB
view details)
File details
Details for the file str2td-0.0.3.tar.gz.
File metadata
- Download URL: str2td-0.0.3.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40f89b999c4f52ddb842943de64bd68898f47f8826e028137b2c08f276517e22
|
|
| MD5 |
c99d70351fced9d3810b78feba2172e0
|
|
| BLAKE2b-256 |
cb54e1ed4ff469f206fe3004f4c6c4b853169bd39a9410c6a6db661535d4430e
|
File details
Details for the file str2td-0.0.3-py3-none-any.whl.
File metadata
- Download URL: str2td-0.0.3-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a71cd0ce61af704a1eb2d07936f7f68a6408ec2783f1b441f9cf9b7c5a84492
|
|
| MD5 |
9a18b8ebf99e4edaafb0f234648a0264
|
|
| BLAKE2b-256 |
86c2555b35c77d89d5f0476744534baf1f23ba041bb5cabd0fc415732d8c5142
|