wag-managment-api-service-v.../api_library/date_time_actions/date_functions.py

53 lines
1.5 KiB
Python

import arrow
import calendar
class DateTimeLocal:
__SYSTEM__: str = "GMT+0"
def __init__(self, timezone: str = "GMT+3", is_client: bool = True):
self.timezone = self.__SYSTEM__
if is_client:
self.timezone = timezone.replace("-", "+")
def find_last_day_of_month(self, date_value):
today = self.get(date_value).date()
_, last_day = calendar.monthrange(today.year, today.month)
return self.get(today.year, today.month, last_day)
def find_first_day_of_month(self, date_value):
today = self.get(date_value).date()
return self.get(today.year, today.month, 1).to(self.timezone)
def get(self, *args):
return arrow.get(*args).to(str(self.timezone))
def now(self):
return arrow.now().to(str(self.timezone))
def shift(self, date, **kwargs):
return self.get(date).shift(**kwargs)
def date(self, date):
return self.get(date).date()
def time(self, date):
return self.get(date).time()
def string_date(self, date, splitter: str = "-"):
return str(self.get(date).date()).replace("-", splitter)
def string_time_only(self, date):
return self.get(date).format("HH:mm:ss")
def string_date_only(self, date):
return self.get(date).format("YYYY-MM-DD")
client_arrow = DateTimeLocal(is_client=True)
system_arrow = DateTimeLocal(is_client=False)
print(client_arrow.string_time_only(arrow.utcnow()))
print(system_arrow.string_time_only(arrow.utcnow()))