Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -41,7 +41,7 @@ RELATIVE_RE = re.compile(
|
|||
r"\s*(?P<quantity>\d+)\s*"
|
||||
r"(?P<unit>(second|sec|s|minute|min|month|mo|m|hour|hr|h|day|d|week|w|year|yr|y))s?"
|
||||
r"(?P<ago>\s+ago)?\s*",
|
||||
re.I
|
||||
re.I,
|
||||
)
|
||||
TIME_SYMBOL_MAP = {
|
||||
"s": "second",
|
||||
|
|
@ -72,9 +72,7 @@ def date_parse(value, default_tz=TZ_UTC):
|
|||
dayfirst = False if YEAR_FIRST_RE.match(value) else True
|
||||
|
||||
try:
|
||||
dt = default_tzinfo(
|
||||
parser.parse(value, dayfirst=dayfirst),
|
||||
default_tz)
|
||||
dt = default_tzinfo(parser.parse(value, dayfirst=dayfirst), default_tz)
|
||||
except ParserError as e:
|
||||
if value == "now":
|
||||
dt = datetime.datetime.now(tz.tzutc())
|
||||
|
|
@ -86,7 +84,8 @@ def date_parse(value, default_tz=TZ_UTC):
|
|||
raise e
|
||||
return calendar.timegm(dt.utctimetuple())
|
||||
|
||||
def date_parse_ext(value: str, default_tz: datetime.tzinfo=TZ_UTC) -> float:
|
||||
|
||||
def date_parse_ext(value: str, default_tz: datetime.tzinfo = TZ_UTC) -> float:
|
||||
"""Extended date parse which accept relative date
|
||||
|
||||
@param value: date to parse, in any format supported by parser
|
||||
|
|
@ -103,10 +102,9 @@ def date_parse_ext(value: str, default_tz: datetime.tzinfo=TZ_UTC) -> float:
|
|||
return date_parse(value, default_tz=default_tz)
|
||||
|
||||
if sum(1 for g in ("direction", "in", "ago") if m.group(g)) > 1:
|
||||
raise ValueError(
|
||||
_('You can use only one of direction (+ or -), "in" and "ago"'))
|
||||
raise ValueError(_('You can use only one of direction (+ or -), "in" and "ago"'))
|
||||
|
||||
if m.group("direction") == '-' or m.group("ago"):
|
||||
if m.group("direction") == "-" or m.group("ago"):
|
||||
direction = -1
|
||||
else:
|
||||
direction = 1
|
||||
|
|
@ -146,7 +144,7 @@ def date_fmt(
|
|||
auto_old_fmt: str = "short",
|
||||
auto_new_fmt: str = "relative",
|
||||
locale_str: str = C.DEFAULT_LOCALE,
|
||||
tz_info: Union[datetime.tzinfo, str] = TZ_UTC
|
||||
tz_info: Union[datetime.tzinfo, str] = TZ_UTC,
|
||||
) -> str:
|
||||
"""Format date according to locale
|
||||
|
||||
|
|
@ -186,8 +184,9 @@ def date_fmt(
|
|||
if auto_limit == 0:
|
||||
now = datetime.datetime.now(tz_info)
|
||||
# we want to use given tz_info, so we don't use date() or today()
|
||||
today = datetime.datetime(year=now.year, month=now.month, day=now.day,
|
||||
tzinfo=now.tzinfo)
|
||||
today = datetime.datetime(
|
||||
year=now.year, month=now.month, day=now.day, tzinfo=now.tzinfo
|
||||
)
|
||||
today = calendar.timegm(today.utctimetuple())
|
||||
if timestamp < today:
|
||||
fmt = auto_old_fmt
|
||||
|
|
@ -210,8 +209,9 @@ def date_fmt(
|
|||
dt = datetime.datetime.fromtimestamp(timestamp, tz_info)
|
||||
return dates.format_date(dt, format=fmt, locale=locale_str)
|
||||
else:
|
||||
return dates.format_datetime(timestamp, format=fmt, locale=locale_str,
|
||||
tzinfo=tz_info)
|
||||
return dates.format_datetime(
|
||||
timestamp, format=fmt, locale=locale_str, tzinfo=tz_info
|
||||
)
|
||||
elif fmt == "iso":
|
||||
if date_only:
|
||||
fmt = "yyyy-MM-dd"
|
||||
|
|
@ -219,8 +219,9 @@ def date_fmt(
|
|||
fmt = "yyyy-MM-ddTHH:mm:ss'Z'"
|
||||
return dates.format_datetime(timestamp, format=fmt)
|
||||
else:
|
||||
return dates.format_datetime(timestamp, format=fmt, locale=locale_str,
|
||||
tzinfo=tz_info)
|
||||
return dates.format_datetime(
|
||||
timestamp, format=fmt, locale=locale_str, tzinfo=tz_info
|
||||
)
|
||||
|
||||
|
||||
def delta2human(start_ts: Union[float, int], end_ts: Union[float, int]) -> str:
|
||||
|
|
@ -234,8 +235,7 @@ def delta2human(start_ts: Union[float, int], end_ts: Union[float, int]) -> str:
|
|||
"end timestamp must be bigger or equal to start timestamp !"
|
||||
)
|
||||
rd = relativedelta(
|
||||
datetime.datetime.fromtimestamp(end_ts),
|
||||
datetime.datetime.fromtimestamp(start_ts)
|
||||
datetime.datetime.fromtimestamp(end_ts), datetime.datetime.fromtimestamp(start_ts)
|
||||
)
|
||||
text_elems = []
|
||||
for unit in ("years", "months", "days", "hours", "minutes"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue