feat(shared): create time functions
This commit is contained in:
parent
9d7d0ee6ca
commit
045fdc8d96
|
@ -0,0 +1,14 @@
|
||||||
|
from datetime import time
|
||||||
|
|
||||||
|
|
||||||
|
def time_in_seconds(value: time) -> float:
|
||||||
|
return (
|
||||||
|
value.hour * 60 * 60
|
||||||
|
+ value.minute * 60
|
||||||
|
+ value.second
|
||||||
|
+ value.microsecond / 1000000.0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def time_in_milliseconds(value: time) -> float:
|
||||||
|
return time_in_seconds(value) * 1000
|
|
@ -0,0 +1,15 @@
|
||||||
|
from datetime import time
|
||||||
|
|
||||||
|
from pytest import approx
|
||||||
|
|
||||||
|
from libretime_shared.datetime import time_in_milliseconds, time_in_seconds
|
||||||
|
|
||||||
|
|
||||||
|
def test_time_in_seconds():
|
||||||
|
value = time(hour=0, minute=3, second=34, microsecond=649600)
|
||||||
|
assert time_in_seconds(value) == approx(214.65, abs=0.009)
|
||||||
|
|
||||||
|
|
||||||
|
def test_time_in_milliseconds():
|
||||||
|
value = time(hour=0, minute=0, second=0, microsecond=500000)
|
||||||
|
assert time_in_milliseconds(value) == 500
|
Loading…
Reference in New Issue