code style reformatting using black
This commit is contained in:
parent
4127bcffd0
commit
744cb0c503
1 changed files with 21394 additions and 10488 deletions
|
|
@ -36,7 +36,15 @@ def date_parse(value):
|
|||
return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple())
|
||||
|
||||
|
||||
def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt='short', auto_new_fmt='relative', locale_str=C.DEFAULT_LOCALE):
|
||||
def date_fmt(
|
||||
timestamp,
|
||||
fmt="short",
|
||||
date_only=False,
|
||||
auto_limit=7,
|
||||
auto_old_fmt="short",
|
||||
auto_new_fmt="relative",
|
||||
locale_str=C.DEFAULT_LOCALE,
|
||||
):
|
||||
"""format date according to locale
|
||||
|
||||
@param timestamp(basestring, int): unix time
|
||||
|
|
@ -63,9 +71,9 @@ def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt
|
|||
than limit
|
||||
|
||||
"""
|
||||
if fmt == 'auto_day':
|
||||
fmt, auto_limit, auto_old_fmt, auto_new_fmt = 'auto', 0, 'short', 'HH:mm'
|
||||
if fmt == 'auto':
|
||||
if fmt == "auto_day":
|
||||
fmt, auto_limit, auto_old_fmt, auto_new_fmt = "auto", 0, "short", "HH:mm"
|
||||
if fmt == "auto":
|
||||
if auto_limit == 0:
|
||||
today = time.mktime(datetime.date.today().timetuple())
|
||||
if int(timestamp) < today:
|
||||
|
|
@ -79,15 +87,17 @@ def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt
|
|||
else:
|
||||
fmt = auto_new_fmt
|
||||
|
||||
if fmt == 'relative':
|
||||
if fmt == "relative":
|
||||
delta = int(timestamp) - time.time()
|
||||
return dates.format_timedelta(delta, granularity="minute", add_direction=True, locale=locale_str)
|
||||
elif fmt in ('short', 'long'):
|
||||
return dates.format_timedelta(
|
||||
delta, granularity="minute", add_direction=True, locale=locale_str
|
||||
)
|
||||
elif fmt in ("short", "long"):
|
||||
formatter = dates.format_date if date_only else dates.format_datetime
|
||||
return formatter(int(timestamp), format=fmt, locale=locale_str)
|
||||
elif fmt == 'iso':
|
||||
elif fmt == "iso":
|
||||
if date_only:
|
||||
fmt = 'yyyy-MM-dd'
|
||||
fmt = "yyyy-MM-dd"
|
||||
else:
|
||||
fmt = "yyyy-MM-ddTHH:mm:ss'Z'"
|
||||
return dates.format_datetime(int(timestamp), format=fmt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue