durationpy 0.10__tar.gz → 0.12__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.
- durationpy-0.12/PKG-INFO +45 -0
- {durationpy-0.10 → durationpy-0.12}/README.md +4 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy/duration.py +28 -16
- durationpy-0.12/durationpy.egg-info/PKG-INFO +45 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy.egg-info/SOURCES.txt +1 -2
- durationpy-0.12/pyproject.toml +22 -0
- durationpy-0.12/setup.cfg +4 -0
- durationpy-0.10/PKG-INFO +0 -10
- durationpy-0.10/durationpy.egg-info/PKG-INFO +0 -10
- durationpy-0.10/setup.cfg +0 -7
- durationpy-0.10/setup.py +0 -14
- {durationpy-0.10 → durationpy-0.12}/LICENSE +0 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy/__init__.py +0 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy/__init__.pyi +0 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy/py.typed +0 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy.egg-info/dependency_links.txt +0 -0
- {durationpy-0.10 → durationpy-0.12}/durationpy.egg-info/top_level.txt +0 -0
durationpy-0.12/PKG-INFO
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: durationpy
|
|
3
|
+
Version: 0.12
|
|
4
|
+
Summary: Module for converting between datetime.timedelta and Go's Duration strings.
|
|
5
|
+
Author-email: Ilia Choly <ilia.choly@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/icholy/durationpy
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# durationpy
|
|
14
|
+
|
|
15
|
+
> Module for converting between `datetime.timedelta` and Go's Duration strings.
|
|
16
|
+
|
|
17
|
+
### Install
|
|
18
|
+
|
|
19
|
+
``` sh
|
|
20
|
+
$ pip install durationpy
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Parse
|
|
25
|
+
|
|
26
|
+
* `ns` - nanoseconds
|
|
27
|
+
* `us` - microseconds
|
|
28
|
+
* `ms` - millisecond
|
|
29
|
+
* `s` - second
|
|
30
|
+
* `m` - minute
|
|
31
|
+
* `h` - hour
|
|
32
|
+
* `d` - day
|
|
33
|
+
* `w` - week
|
|
34
|
+
* `mm` - month
|
|
35
|
+
* `y` - year
|
|
36
|
+
|
|
37
|
+
``` py
|
|
38
|
+
# parse
|
|
39
|
+
td = durationpy.from_str("4h3m2s1ms")
|
|
40
|
+
|
|
41
|
+
# format
|
|
42
|
+
durationpy.to_str(td)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Note:** nanosecond precision is lost because `datetime.timedelta` uses microsecond resolution.
|
|
@@ -50,15 +50,16 @@ def from_str(duration):
|
|
|
50
50
|
sign = -1
|
|
51
51
|
duration = duration[1:]
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
if not matches:
|
|
53
|
+
if not duration:
|
|
55
54
|
raise DurationError("Invalid duration {}".format(original))
|
|
56
|
-
if matches[0].start() != 0 or matches[-1].end() != len(duration):
|
|
57
|
-
raise DurationError(
|
|
58
|
-
'Extra chars at start or end of duration {}'.format(original))
|
|
59
55
|
|
|
60
56
|
total = 0
|
|
61
|
-
|
|
57
|
+
pos = 0
|
|
58
|
+
while pos < len(duration):
|
|
59
|
+
match = _duration_re.match(duration, pos)
|
|
60
|
+
if not match:
|
|
61
|
+
raise DurationError("Invalid duration {}".format(original))
|
|
62
|
+
pos = match.end()
|
|
62
63
|
value, unit = match.groups()
|
|
63
64
|
if unit not in units:
|
|
64
65
|
raise DurationError(
|
|
@@ -70,7 +71,15 @@ def from_str(duration):
|
|
|
70
71
|
"Invalid value {} in duration {}".format(value, original))
|
|
71
72
|
|
|
72
73
|
microseconds = total / _microsecond_size
|
|
73
|
-
|
|
74
|
+
try:
|
|
75
|
+
return datetime.timedelta(microseconds=sign * microseconds)
|
|
76
|
+
except (OverflowError, ValueError) as e:
|
|
77
|
+
# A huge value overflows timedelta's day count, and a value large enough
|
|
78
|
+
# to become float inf makes timedelta reject it too. Report either as a
|
|
79
|
+
# DurationError instead of leaking the raw exception.
|
|
80
|
+
raise DurationError(
|
|
81
|
+
"Duration out of range: {}".format(original)
|
|
82
|
+
) from e
|
|
74
83
|
|
|
75
84
|
def to_str(delta, extended=False):
|
|
76
85
|
"""Format a datetime.timedelta to a duration string"""
|
|
@@ -119,31 +128,34 @@ def _to_str_large(nanoseconds, extended):
|
|
|
119
128
|
years = int(nanoseconds / _year_size)
|
|
120
129
|
if years:
|
|
121
130
|
nanoseconds -= _year_size * years
|
|
122
|
-
result_str += "{
|
|
131
|
+
result_str += "{}y".format(years)
|
|
123
132
|
|
|
124
133
|
months = int(nanoseconds / _month_size)
|
|
125
134
|
if months:
|
|
126
135
|
nanoseconds -= _month_size * months
|
|
127
|
-
result_str += "{
|
|
136
|
+
result_str += "{}mm".format(months)
|
|
128
137
|
|
|
129
138
|
days = int(nanoseconds / _day_size)
|
|
130
139
|
if days:
|
|
131
140
|
nanoseconds -= _day_size * days
|
|
132
|
-
result_str += "{
|
|
141
|
+
result_str += "{}d".format(days)
|
|
133
142
|
|
|
134
143
|
hours = int(nanoseconds / _hour_size)
|
|
135
144
|
if hours:
|
|
136
145
|
nanoseconds -= _hour_size * hours
|
|
137
|
-
result_str += "{
|
|
146
|
+
result_str += "{}h".format(hours)
|
|
138
147
|
|
|
139
148
|
minutes = int(nanoseconds / _minute_size)
|
|
140
149
|
if minutes:
|
|
141
150
|
nanoseconds -= _minute_size * minutes
|
|
142
|
-
result_str += "{
|
|
151
|
+
result_str += "{}m".format(minutes)
|
|
143
152
|
|
|
144
|
-
seconds =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
seconds = int(nanoseconds / _second_size)
|
|
154
|
+
nanoseconds = int(nanoseconds - _second_size * seconds)
|
|
155
|
+
if nanoseconds:
|
|
156
|
+
fraction = "{:09d}".format(nanoseconds).rstrip("0")
|
|
157
|
+
result_str += "{}.{}s".format(seconds, fraction)
|
|
158
|
+
elif seconds:
|
|
159
|
+
result_str += "{}s".format(seconds)
|
|
148
160
|
|
|
149
161
|
return result_str
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: durationpy
|
|
3
|
+
Version: 0.12
|
|
4
|
+
Summary: Module for converting between datetime.timedelta and Go's Duration strings.
|
|
5
|
+
Author-email: Ilia Choly <ilia.choly@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/icholy/durationpy
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# durationpy
|
|
14
|
+
|
|
15
|
+
> Module for converting between `datetime.timedelta` and Go's Duration strings.
|
|
16
|
+
|
|
17
|
+
### Install
|
|
18
|
+
|
|
19
|
+
``` sh
|
|
20
|
+
$ pip install durationpy
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Parse
|
|
25
|
+
|
|
26
|
+
* `ns` - nanoseconds
|
|
27
|
+
* `us` - microseconds
|
|
28
|
+
* `ms` - millisecond
|
|
29
|
+
* `s` - second
|
|
30
|
+
* `m` - minute
|
|
31
|
+
* `h` - hour
|
|
32
|
+
* `d` - day
|
|
33
|
+
* `w` - week
|
|
34
|
+
* `mm` - month
|
|
35
|
+
* `y` - year
|
|
36
|
+
|
|
37
|
+
``` py
|
|
38
|
+
# parse
|
|
39
|
+
td = durationpy.from_str("4h3m2s1ms")
|
|
40
|
+
|
|
41
|
+
# format
|
|
42
|
+
durationpy.to_str(td)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Note:** nanosecond precision is lost because `datetime.timedelta` uses microsecond resolution.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "durationpy"
|
|
7
|
+
version = "0.12"
|
|
8
|
+
description = "Module for converting between datetime.timedelta and Go's Duration strings."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Ilia Choly", email = "ilia.choly@gmail.com" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/icholy/durationpy"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools]
|
|
19
|
+
packages = ["durationpy"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools.package-data]
|
|
22
|
+
durationpy = ["py.typed", "*.pyi"]
|
durationpy-0.10/PKG-INFO
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: durationpy
|
|
3
|
-
Version: 0.10
|
|
4
|
-
Summary: Module for converting between datetime.timedelta and Go's Duration strings.
|
|
5
|
-
Home-page: https://github.com/icholy/durationpy
|
|
6
|
-
Download-URL: https://github.com/icholy/durationpy/tarball/0.10
|
|
7
|
-
Author: Ilia Choly
|
|
8
|
-
Author-email: ilia.choly@gmail.com
|
|
9
|
-
License: MIT
|
|
10
|
-
License-File: LICENSE
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: durationpy
|
|
3
|
-
Version: 0.10
|
|
4
|
-
Summary: Module for converting between datetime.timedelta and Go's Duration strings.
|
|
5
|
-
Home-page: https://github.com/icholy/durationpy
|
|
6
|
-
Download-URL: https://github.com/icholy/durationpy/tarball/0.10
|
|
7
|
-
Author: Ilia Choly
|
|
8
|
-
Author-email: ilia.choly@gmail.com
|
|
9
|
-
License: MIT
|
|
10
|
-
License-File: LICENSE
|
durationpy-0.10/setup.cfg
DELETED
durationpy-0.10/setup.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name = 'durationpy',
|
|
5
|
-
description = 'Module for converting between datetime.timedelta and Go\'s Duration strings.',
|
|
6
|
-
url = 'https://github.com/icholy/durationpy',
|
|
7
|
-
author = 'Ilia Choly',
|
|
8
|
-
author_email = 'ilia.choly@gmail.com',
|
|
9
|
-
download_url = 'https://github.com/icholy/durationpy/tarball/0.10',
|
|
10
|
-
version = '0.10',
|
|
11
|
-
packages = ['durationpy'],
|
|
12
|
-
package_data = {'durationpy': ['py.typed', '*.pyi']},
|
|
13
|
-
license = 'MIT'
|
|
14
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|