durationpy 0.11__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.11 → durationpy-0.12}/durationpy/duration.py +19 -15
- durationpy-0.12/durationpy.egg-info/PKG-INFO +45 -0
- {durationpy-0.11 → 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.11/PKG-INFO +0 -17
- durationpy-0.11/durationpy.egg-info/PKG-INFO +0 -17
- durationpy-0.11/setup.cfg +0 -7
- durationpy-0.11/setup.py +0 -14
- {durationpy-0.11 → durationpy-0.12}/LICENSE +0 -0
- {durationpy-0.11 → durationpy-0.12}/README.md +0 -0
- {durationpy-0.11 → durationpy-0.12}/durationpy/__init__.py +0 -0
- {durationpy-0.11 → durationpy-0.12}/durationpy/__init__.pyi +0 -0
- {durationpy-0.11 → durationpy-0.12}/durationpy/py.typed +0 -0
- {durationpy-0.11 → durationpy-0.12}/durationpy.egg-info/dependency_links.txt +0 -0
- {durationpy-0.11 → 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(
|
|
@@ -127,31 +128,34 @@ def _to_str_large(nanoseconds, extended):
|
|
|
127
128
|
years = int(nanoseconds / _year_size)
|
|
128
129
|
if years:
|
|
129
130
|
nanoseconds -= _year_size * years
|
|
130
|
-
result_str += "{
|
|
131
|
+
result_str += "{}y".format(years)
|
|
131
132
|
|
|
132
133
|
months = int(nanoseconds / _month_size)
|
|
133
134
|
if months:
|
|
134
135
|
nanoseconds -= _month_size * months
|
|
135
|
-
result_str += "{
|
|
136
|
+
result_str += "{}mm".format(months)
|
|
136
137
|
|
|
137
138
|
days = int(nanoseconds / _day_size)
|
|
138
139
|
if days:
|
|
139
140
|
nanoseconds -= _day_size * days
|
|
140
|
-
result_str += "{
|
|
141
|
+
result_str += "{}d".format(days)
|
|
141
142
|
|
|
142
143
|
hours = int(nanoseconds / _hour_size)
|
|
143
144
|
if hours:
|
|
144
145
|
nanoseconds -= _hour_size * hours
|
|
145
|
-
result_str += "{
|
|
146
|
+
result_str += "{}h".format(hours)
|
|
146
147
|
|
|
147
148
|
minutes = int(nanoseconds / _minute_size)
|
|
148
149
|
if minutes:
|
|
149
150
|
nanoseconds -= _minute_size * minutes
|
|
150
|
-
result_str += "{
|
|
151
|
+
result_str += "{}m".format(minutes)
|
|
151
152
|
|
|
152
|
-
seconds =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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)
|
|
156
160
|
|
|
157
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.11/PKG-INFO
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: durationpy
|
|
3
|
-
Version: 0.11
|
|
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.11
|
|
7
|
-
Author: Ilia Choly
|
|
8
|
-
Author-email: ilia.choly@gmail.com
|
|
9
|
-
License: MIT
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Dynamic: author
|
|
12
|
-
Dynamic: author-email
|
|
13
|
-
Dynamic: download-url
|
|
14
|
-
Dynamic: home-page
|
|
15
|
-
Dynamic: license
|
|
16
|
-
Dynamic: license-file
|
|
17
|
-
Dynamic: summary
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: durationpy
|
|
3
|
-
Version: 0.11
|
|
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.11
|
|
7
|
-
Author: Ilia Choly
|
|
8
|
-
Author-email: ilia.choly@gmail.com
|
|
9
|
-
License: MIT
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Dynamic: author
|
|
12
|
-
Dynamic: author-email
|
|
13
|
-
Dynamic: download-url
|
|
14
|
-
Dynamic: home-page
|
|
15
|
-
Dynamic: license
|
|
16
|
-
Dynamic: license-file
|
|
17
|
-
Dynamic: summary
|
durationpy-0.11/setup.cfg
DELETED
durationpy-0.11/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.11',
|
|
10
|
-
version = '0.11',
|
|
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
|
|
File without changes
|