feat: drop Python 3.6 support
This commit is contained in:
parent
448cff7600
commit
d29d837d01
9 changed files with 14 additions and 49 deletions
|
@ -1,4 +1,4 @@
|
|||
from datetime import datetime, time
|
||||
from datetime import time
|
||||
|
||||
|
||||
def time_in_seconds(value: time) -> float:
|
||||
|
@ -12,16 +12,3 @@ def time_in_seconds(value: time) -> float:
|
|||
|
||||
def time_in_milliseconds(value: time) -> float:
|
||||
return time_in_seconds(value) * 1000
|
||||
|
||||
|
||||
def time_fromisoformat(value: str) -> time:
|
||||
"""
|
||||
This is required for Python 3.6 support. datetime.time.fromisoformat was
|
||||
only added in Python 3.7. Until LibreTime drops Python 3.6 support, this
|
||||
wrapper uses the old way of doing it.
|
||||
"""
|
||||
try:
|
||||
obj = datetime.strptime(value, "%H:%M:%S.%f")
|
||||
except ValueError:
|
||||
obj = datetime.strptime(value, "%H:%M:%S")
|
||||
return obj.time()
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
from datetime import time
|
||||
|
||||
from pytest import approx, mark
|
||||
from pytest import approx
|
||||
|
||||
from libretime_shared.datetime import (
|
||||
time_fromisoformat,
|
||||
time_in_milliseconds,
|
||||
time_in_seconds,
|
||||
)
|
||||
from libretime_shared.datetime import time_in_milliseconds, time_in_seconds
|
||||
|
||||
|
||||
def test_time_in_seconds():
|
||||
|
@ -17,15 +13,3 @@ def test_time_in_seconds():
|
|||
def test_time_in_milliseconds():
|
||||
value = time(hour=0, minute=0, second=0, microsecond=500000)
|
||||
assert time_in_milliseconds(value) == 500
|
||||
|
||||
|
||||
@mark.parametrize(
|
||||
"payload, expected",
|
||||
[
|
||||
("00:00:00.500000", time(microsecond=500000)),
|
||||
("00:04:30.092540", time(minute=4, second=30, microsecond=92540)),
|
||||
("00:04:30", time(minute=4, second=30)),
|
||||
],
|
||||
)
|
||||
def test_time_fromisoformat(payload, expected):
|
||||
assert time_fromisoformat(payload) == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue