Skip to content

Commit

Permalink
时间提取支持xx个月前
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Oct 14, 2021
1 parent 4660c57 commit 460af24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion feapder/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.9-beta1
1.6.9-beta2
8 changes: 7 additions & 1 deletion feapder/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,12 @@ def transform_lower_num(data_str: str):

@run_safe_model("format_time")
def format_time(release_time, date_format="%Y-%m-%d %H:%M:%S"):
"""
>>> format_time("2个月前")
'2021-08-15 16:24:21'
>>> format_time("2月前")
'2021-08-15 16:24:36'
"""
release_time = transform_lower_num(release_time)
release_time = release_time.replace("日", "天").replace("/", "-")

Expand All @@ -1578,7 +1584,7 @@ def format_time(release_time, date_format="%Y-%m-%d %H:%M:%S"):
release_time = years_ago.strftime("%Y-%m-%d %H:%M:%S")

elif "月前" in release_time:
months = re.compile("(\d+)\s*月前").findall(release_time)
months = re.compile("(\d+)[\s个]*月前").findall(release_time)
months_ago = datetime.datetime.now() - datetime.timedelta(
days=int(months[0]) * 30
)
Expand Down

0 comments on commit 460af24

Please sign in to comment.