From f49047ef33a0e3ac70cac789df887707ce31f421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Sun, 10 Sep 2023 11:19:34 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE | 21 ++++++++++++++ README.md | 3 ++ notime/__init__.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 notime/__init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8275007 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Julian Müller (ChaoticByte) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5eb5029 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# notime + +notime is a simple python library that represents the daytime on a scale of `0` - `100000000` in a most probably mathematically inaccurate way. diff --git a/notime/__init__.py b/notime/__init__.py new file mode 100644 index 0000000..b93fe8a --- /dev/null +++ b/notime/__init__.py @@ -0,0 +1,72 @@ + +MILLISECONDS_PER_DAY = 86400000 +FORMAT_MAX = 100000000 + + +def ms_to_notime(value:int) -> int: + return round(float(value % MILLISECONDS_PER_DAY) + * (float(FORMAT_MAX) / float(MILLISECONDS_PER_DAY))) % FORMAT_MAX + +def notime_to_ms(value:int) -> int: + return round(float(value % FORMAT_MAX) + * (float(MILLISECONDS_PER_DAY) / float(FORMAT_MAX))) % MILLISECONDS_PER_DAY + + +class notime: + + def __init__(self, value:int): + self.value = round(value) % FORMAT_MAX + + @classmethod + def from_time(cls, hour:int, minute:int, second:int, millisecond:int): + hour = round(hour) % 24 + minute = round(minute) % 60 + second = round(second) % 60 + millisecond = round(millisecond) % 1000 + sum_ = (hour * 60 * 60 * 1000)\ + + (minute * 60 * 1000)\ + + (second * 1000)\ + + millisecond + return cls(ms_to_notime(sum_)) + + def to_ms(self): + return notime_to_ms(self.value) + + def __repr__(self): + return repr(self.value) + + def __str__(self): + return str(self.value) + + def __int__(self): + return self.value + + def __add__(self, value:int): + return self.__class__(self.value + value) + + def __sub__(self, value:int): + return self.__class__(self.value - value) + + def __mul__(self, value:int): + return self.__class__(self.value * value) + + def __truediv__(self, value:float): + return self.__class__(float(self.value) / float(value)) + + def __pow__(self, value:int): + return self.__class__(float(self.value) ** float(value)) + + def __eq__(self, value:int): + return self.value == value + + def __gt__(self, value:int): + return self.value > value + + def __ge__(self, value:int): + return self.value >= value + + def __lt__(self, value:int): + return self.value < value + + def __le__(self, value:int): + return self.value <= value