Skip to content

Commit

Permalink
feat: extra units for Time
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 20, 2024
1 parent 658f3de commit 21a4696
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generate/generate_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def _generat_zero_function(current_class: str) -> list[str]:
"minutes": "60",
"seconds": "1",
"milliseconds": "10**-3",
"microseconds": "10**-6",
"nanoseconds": "10**-9",
},
"Velocity": {
"meters_per_second": "1",
Expand Down
14 changes: 14 additions & 0 deletions quantio/quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,19 +597,33 @@ def milliseconds(self) -> float:
"""The time in milliseconds."""
return self._base_value / 10**-3

@property
def microseconds(self) -> float:
"""The time in microseconds."""
return self._base_value / 10**-6

@property
def nanoseconds(self) -> float:
"""The time in nanoseconds."""
return self._base_value / 10**-9

def __init__(
self,
_base_value: float = 0.0,
hours: float = 0.0,
minutes: float = 0.0,
seconds: float = 0.0,
milliseconds: float = 0.0,
microseconds: float = 0.0,
nanoseconds: float = 0.0,
) -> None:
self._base_value = _base_value
self._base_value += hours * 60 * 60
self._base_value += minutes * 60
self._base_value += seconds * 1
self._base_value += milliseconds * 10**-3
self._base_value += microseconds * 10**-6
self._base_value += nanoseconds * 10**-9

@classmethod
def zero(cls) -> Time:
Expand Down

0 comments on commit 21a4696

Please sign in to comment.