Skip to content

Commit

Permalink
Update util.py
Browse files Browse the repository at this point in the history
  • Loading branch information
1989Ryan authored Apr 22, 2024
1 parent b116a40 commit a8d6b24
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions _cite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml
from yaml.loader import SafeLoader
from pathlib import Path
from datetime import datetime
from datetime import date, datetime
from rich import print
from diskcache import Cache

Expand Down Expand Up @@ -88,15 +88,17 @@ def list_of_dicts(data):
return isinstance(data, list) and all(isinstance(entry, dict) for entry in data)


def format_date(date):
def format_date(_date):
"""
format date as YYYY-MM-DD, or no date if malformed
"""

if isinstance(date, int):
return datetime.fromtimestamp(date // 1000.0).strftime("%Y-%m-%d")
if isinstance(_date, int):
return datetime.fromtimestamp(_date // 1000.0).strftime("%Y-%m-%d")
if isinstance(_date, (date, datetime)):
return _date.strftime("%Y-%m-%d")
try:
return datetime.strptime(date, "%Y-%m-%d").strftime("%Y-%m-%d")
return datetime.strptime(_date, "%Y-%m-%d").strftime("%Y-%m-%d")
except Exception:
return ""

Expand Down

0 comments on commit a8d6b24

Please sign in to comment.