Skip to content

Commit

Permalink
functions_date.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ufoptg authored Sep 16, 2024
1 parent 4a49d26 commit 11fe9a5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions RyuzakiLib/functions_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from datetime import datetime

data = {
"7117444122": 1723429195,
"6602485156": 1723148395,
"5396587273": 1648014800,
"5336336790": 1646368100,
"4317845111": 1620028800,
Expand All @@ -34,29 +36,31 @@
}

class UserDateEstimator:
def __init__(self, order = 3):
self.order = 3

def __init__(self, order=3):
self.order = order
self.x, self.y = self._unpack_data()
self._func = self._fit_data()

def _unpack_data(self):
x_data = np.array(list(map(int, data.keys())))
y_data = np.array(list(data.values()))
return (x_data, y_data)
return x_data, y_data

def _fit_data(self):
fitted = np.polyfit(self.x, self.y, self.order)
return np.poly1d(fitted)

def func(self, tg_id: int):
# Check if tg_id exists in the data
if str(tg_id) in data:
return data[str(tg_id)] # Return exact value if found
value = self._func(tg_id)
if value > time.time():
value = time.time()
return value

def time_format(self, unix_time, fmt="%Y-%m-%d"):
result = [str(datetime.utcfromtimestamp(unix_time).strftime(fmt))]
def time_format(self, unix_time):
formatted_date = datetime.utcfromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
d = relativedelta(datetime.now(), datetime.utcfromtimestamp(unix_time))
result.append(f"{d.years} year{'s' if d.years != 1 else ''}, {d.months} month{'s' if d.months != 1 else ''}, {d.days} day{'s' if d.days != 1 else ''}")
return result
age = f"{d.years} year{'s' if d.years != 1 else ''}, {d.months} month{'s' if d.months != 1 else ''}, {d.days} day{'s' if d.days != 1 else ''}"
return formatted_date, age

0 comments on commit 11fe9a5

Please sign in to comment.