mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
add new methods for date/time output
This commit is contained in:
parent
503a2adc38
commit
5266e10140
@ -10,6 +10,8 @@ import datetime as dt
|
||||
import pytz
|
||||
|
||||
DATE_STR_FORMAT = "%H:%M:%S %d-%m-%Y"
|
||||
DATE_SHORT_STR_FORMAT = "%Y-%m-%d"
|
||||
TIME_SHORT_STR_FORMAT = "%H:%M"
|
||||
UTC = DEFAULT_TIME_ZONE = pytz.utc
|
||||
|
||||
|
||||
@ -79,6 +81,22 @@ def datetime_to_str(dattim):
|
||||
return dattim.strftime(DATE_STR_FORMAT)
|
||||
|
||||
|
||||
def datetime_to_short_time_str(dattim):
|
||||
""" Converts datetime to a string format as short time.
|
||||
|
||||
@rtype : str
|
||||
"""
|
||||
return dattim.strftime(TIME_SHORT_STR_FORMAT)
|
||||
|
||||
|
||||
def datetime_to_short_date_str(dattim):
|
||||
""" Converts datetime to a string format as short date.
|
||||
|
||||
@rtype : str
|
||||
"""
|
||||
return dattim.strftime(DATE_SHORT_STR_FORMAT)
|
||||
|
||||
|
||||
def str_to_datetime(dt_str):
|
||||
""" Converts a string to a UTC datetime object.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user