Initial commit
This commit is contained in:
commit
f49047ef33
4 changed files with 97 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
__pycache__
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -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.
|
72
notime/__init__.py
Normal file
72
notime/__init__.py
Normal file
|
@ -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
|
Reference in a new issue