forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): reporting revamp, part 1 (datahub-project#7031)
- Loading branch information
Showing
12 changed files
with
267 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
metadata-ingestion/src/datahub/ingestion/api/report_helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import humanfriendly | ||
|
||
|
||
def format_datetime_relative(some_val: datetime) -> str: | ||
"""Formats a datetime as a human-readable string relative to now.""" | ||
|
||
# check if we have a tz_aware object or not (https://stackoverflow.com/questions/5802108/how-to-check-if-a-datetime-object-is-localized-with-pytz) | ||
tz_aware = ( | ||
some_val.tzinfo is not None and some_val.tzinfo.utcoffset(some_val) is not None | ||
) | ||
now = datetime.now(timezone.utc) if tz_aware else datetime.now() | ||
diff = now - some_val | ||
if abs(diff) < timedelta(seconds=1): | ||
# the timestamps are close enough that printing a duration isn't useful | ||
return f"{some_val} (now)" | ||
elif diff > timedelta(seconds=0): | ||
# timestamp is in the past | ||
return f"{some_val} ({humanfriendly.format_timespan(diff)} ago)" | ||
else: | ||
# timestamp is in the future | ||
return f"{some_val} (in {humanfriendly.format_timespan(some_val - now)})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.