mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
move functions from openpype.lib.config to openpype.lib.dateutils
This commit is contained in:
parent
297aaa6ee1
commit
31a3911d4e
6 changed files with 134 additions and 79 deletions
|
|
@ -1,82 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Get configuration data."""
|
||||
import datetime
|
||||
import warnings
|
||||
import functools
|
||||
|
||||
|
||||
def get_datetime_data(datetime_obj=None):
|
||||
"""Returns current datetime data as dictionary.
|
||||
class ConfigDeprecatedWarning(DeprecationWarning):
|
||||
pass
|
||||
|
||||
Args:
|
||||
datetime_obj (datetime): Specific datetime object
|
||||
|
||||
Returns:
|
||||
dict: prepared date & time data
|
||||
def deprecated(func):
|
||||
"""Mark functions as deprecated.
|
||||
|
||||
Available keys:
|
||||
"d" - <Day of month number> in shortest possible way.
|
||||
"dd" - <Day of month number> with 2 digits.
|
||||
"ddd" - <Week day name> shortened week day. e.g.: `Mon`, ...
|
||||
"dddd" - <Week day name> full name of week day. e.g.: `Monday`, ...
|
||||
"m" - <Month number> in shortest possible way. e.g.: `1` if January
|
||||
"mm" - <Month number> with 2 digits.
|
||||
"mmm" - <Month name> shortened month name. e.g.: `Jan`, ...
|
||||
"mmmm" - <Month name> full month name. e.g.: `January`, ...
|
||||
"yy" - <Year number> shortened year. e.g.: `19`, `20`, ...
|
||||
"yyyy" - <Year number> full year. e.g.: `2019`, `2020`, ...
|
||||
"H" - <Hours number 24-hour> shortened hours.
|
||||
"HH" - <Hours number 24-hour> with 2 digits.
|
||||
"h" - <Hours number 12-hour> shortened hours.
|
||||
"hh" - <Hours number 12-hour> with 2 digits.
|
||||
"ht" - <Midday type> AM or PM.
|
||||
"M" - <Minutes number> shortened minutes.
|
||||
"MM" - <Minutes number> with 2 digits.
|
||||
"S" - <Seconds number> shortened seconds.
|
||||
"SS" - <Seconds number> with 2 digits.
|
||||
It will result in a warning being emitted when the function is used.
|
||||
"""
|
||||
|
||||
if not datetime_obj:
|
||||
datetime_obj = datetime.datetime.now()
|
||||
|
||||
year = datetime_obj.strftime("%Y")
|
||||
|
||||
month = datetime_obj.strftime("%m")
|
||||
month_name_full = datetime_obj.strftime("%B")
|
||||
month_name_short = datetime_obj.strftime("%b")
|
||||
day = datetime_obj.strftime("%d")
|
||||
|
||||
weekday_full = datetime_obj.strftime("%A")
|
||||
weekday_short = datetime_obj.strftime("%a")
|
||||
|
||||
hours = datetime_obj.strftime("%H")
|
||||
hours_midday = datetime_obj.strftime("%I")
|
||||
hour_midday_type = datetime_obj.strftime("%p")
|
||||
minutes = datetime_obj.strftime("%M")
|
||||
seconds = datetime_obj.strftime("%S")
|
||||
|
||||
return {
|
||||
"d": str(int(day)),
|
||||
"dd": str(day),
|
||||
"ddd": weekday_short,
|
||||
"dddd": weekday_full,
|
||||
"m": str(int(month)),
|
||||
"mm": str(month),
|
||||
"mmm": month_name_short,
|
||||
"mmmm": month_name_full,
|
||||
"yy": str(year[2:]),
|
||||
"yyyy": str(year),
|
||||
"H": str(int(hours)),
|
||||
"HH": str(hours),
|
||||
"h": str(int(hours_midday)),
|
||||
"hh": str(hours_midday),
|
||||
"ht": hour_midday_type,
|
||||
"M": str(int(minutes)),
|
||||
"MM": str(minutes),
|
||||
"S": str(int(seconds)),
|
||||
"SS": str(seconds),
|
||||
}
|
||||
@functools.wraps(func)
|
||||
def new_func(*args, **kwargs):
|
||||
warnings.simplefilter("always", ConfigDeprecatedWarning)
|
||||
warnings.warn(
|
||||
(
|
||||
"Deprecated import of function '{}'."
|
||||
" Class was moved to 'openpype.lib.dateutils.{}'."
|
||||
" Please change your imports."
|
||||
).format(func.__name__),
|
||||
category=ConfigDeprecatedWarning
|
||||
)
|
||||
return func(*args, **kwargs)
|
||||
return new_func
|
||||
|
||||
|
||||
@deprecated
|
||||
def get_datetime_data(datetime_obj=None):
|
||||
from .dateutils import get_datetime_data
|
||||
|
||||
return get_datetime_data(datetime_obj)
|
||||
|
||||
|
||||
@deprecated
|
||||
def get_formatted_current_time():
|
||||
return datetime.datetime.now().strftime(
|
||||
"%Y%m%dT%H%M%SZ"
|
||||
)
|
||||
from .dateutils import get_formatted_current_time
|
||||
|
||||
return get_formatted_current_time()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue