# DateUtils
La clase DateUtils ofrece métodos de validación de fecha, hora, generación de timestamp, unix, etc...
# Métodos disponibles
is_valid_date
get_timestamp
today
get_current_time
get_current_hour
compare_dates
fix_time
compare_times
get_current_unix_time
from_unix_time
to_unix_time
day_of_week
to_date
add_months
add_days
get_next_month
days_between_dates
# is_valid_date
@staticmethod
def is_valid_date(current_date):
...
# get_timestamp
@staticmethod
def get_timestamp():
...
# today
@staticmethod
def today(format_date=None, type_format='str'):
...
# get_current_time
@staticmethod
def get_current_time():
...
# get_current_hour
@staticmethod
def get_current_hour():
...
# compare_dates
@classmethod
def compare_dates(init_date=None, end_date=None, compare='eq'):
...
# fix_time
@classmethod
def fix_time(_time=None):
...
# compare_times
@staticmethod
def compare_times(init_time=None, end_time=None, compare='eq'):
...
# get_current_unix_time
@staticmethod
def get_current_unix_time():
...
# from_unix_time
@staticmethod
def from_unix_time(unix_time):
...
# to_unix_time
@staticmethod
def to_unix_time(init_date, init_hour=None):
...
# day_of_week
@staticmethod
def day_of_week(init_date):
...
# to_date
@staticmethod
def to_date(current_date, current_format, new_format=None, type_format='str'):
...
# add_months
@staticmethod
def add_months(add_months=1, init_date=None):
...
# add_days
@staticmethod
def add_days(current_date, num_days=None):
...
# get_next_month
@staticmethod
def get_next_month(init_date=None):
...
# days_between_dates
@staticmethod
def days_between_dates(init_date, end_date):
...
# Un ejemplo
from app.ext.utils import DateUtils
...
created_at = DateUtils.get_timestamp()
print("created_at:", created_at)
current_day = DateUtils.today()
print("current_day:", current_day)
day_of_week = DateUtils.day_of_week(current_day)
print("day_of_week:", day_of_week)
unix_time = DateUtils.to_unix_time(current_day)
print("unix_time:", unix_time)
date_from_unix = DateUtils.from_unix_time(unix_time)
print("date_from_unix:", date_from_unix)
El resultado del ejemplo anterior, en caso de que todo esté bien:
>>> created_at: 20201020194258
>>> current_day: 2020-10-20
>>> day_of_week: {'calendar_day': 'Tuesday', 'week_day': 2}
>>> unix_time: 1603170000.0
>>> date_from_unix: 2020-10-20 00:00:00
# Issues
Para cualquier duda, comentario, sugerencia ó aporte, dirigete a la sección de issues. (opens new window) Antes de abrir un issue nuevo, revisa los ya existentes, en busca de una solución (posiblemente ya planteada) para el problema que se te presenta.