htd 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
htd-0.0.1/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright © 2025 – Bixoto.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
htd-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.3
2
+ Name: htd
3
+ Version: 0.0.1
4
+ Summary: Parse time deltas from human-readable strings
5
+ Author: Baptiste Fontaine
6
+ Author-email: baptiste@bixoto.com
7
+ Requires-Python: >=3.9
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Description-Content-Type: text/markdown
15
+
16
+ # htd
17
+
18
+ **htd** stands for **h**uman **t**ime **d**elta and is a micro-library to parse strings such as `7d4h`
19
+ into `timedelta(days=7, hours=4)`.
20
+
21
+ ## Install
22
+
23
+ pip install htd
24
+
25
+ With Poetry:
26
+
27
+ poetry add htd
28
+
29
+ ## Usage
30
+
31
+ ```python
32
+ import htd
33
+
34
+ htd.parse("7d")
35
+ # => datetime.timedelta(days=7)
36
+ ```
37
+
htd-0.0.1/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # htd
2
+
3
+ **htd** stands for **h**uman **t**ime **d**elta and is a micro-library to parse strings such as `7d4h`
4
+ into `timedelta(days=7, hours=4)`.
5
+
6
+ ## Install
7
+
8
+ pip install htd
9
+
10
+ With Poetry:
11
+
12
+ poetry add htd
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ import htd
18
+
19
+ htd.parse("7d")
20
+ # => datetime.timedelta(days=7)
21
+ ```
@@ -0,0 +1,27 @@
1
+ import re
2
+ from datetime import timedelta
3
+
4
+ __all__ = ['parse', '__version__']
5
+ __version__ = '0.0.1'
6
+
7
+ SYMBOLS = {
8
+ "s": 1,
9
+ "m": 60,
10
+ "h": 60 * 60,
11
+ "d": 60 * 60 * 24,
12
+ "w": 60 * 60 * 24 * 7,
13
+ }
14
+
15
+ RE = re.compile(rf"(\d+(?:\.\d+)?[{''.join(SYMBOLS)}])")
16
+
17
+
18
+ def parse(s: str):
19
+ """
20
+ Parse a string such as `"2d4h10s"` and return a `datetime.timedelta` object.
21
+ """
22
+ total_seconds = 0.0
23
+ for fragment in RE.findall(s):
24
+ unit = fragment[-1]
25
+ total_seconds += float(fragment[:-1]) * SYMBOLS[unit]
26
+
27
+ return timedelta(seconds=total_seconds)
htd-0.0.1/htd/py.typed ADDED
File without changes
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "htd"
3
+ version = "0.0.1"
4
+ description = "Parse time deltas from human-readable strings"
5
+ authors = [
6
+ {name = "Baptiste Fontaine",email = "baptiste@bixoto.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.9"
10
+ dependencies = []
11
+
12
+ [build-system]
13
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
14
+ build-backend = "poetry.core.masonry.api"
15
+
16
+ [tool.poetry.group.dev.dependencies]
17
+ mypy = "^1"
18
+ pytest = "^8"
19
+ ruff = "^0.9"
20
+ pytest-cov = "^6.0"
21
+