JOJ3-config-generator/joj3_config_generator/models/common.py
李衍志523370910113 38f0bc8598
Some checks failed
build / build (pull_request) Failing after 2m20s
build / build (push) Failing after 2m23s
chore: remove outdated FIXME
2025-03-05 15:21:35 +08:00

20 lines
605 B
Python

from typing import Union
import humanfriendly
class Memory(int):
def __new__(cls, value: Union[str, int]) -> "Memory":
if isinstance(value, str):
parsed = humanfriendly.parse_size(value, binary=True)
return super().__new__(cls, parsed)
return super().__new__(cls, value)
class Time(int):
def __new__(cls, value: Union[str, int]) -> "Time":
if isinstance(value, str):
parsed = humanfriendly.parse_timespan(value) * 1_000_000_000 # ns
return super().__new__(cls, round(parsed))
return super().__new__(cls, value)