Skip to content

Commit

Permalink
handle future timestamps and import get_relative_time
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-work committed Jan 6, 2025
1 parent 6adfe8b commit 6573837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from daras_ai_v2.urls import paginate_button, paginate_queryset
from daras_ai_v2.user_date_widgets import render_local_dt_attrs
from daras_ai_v2.variables_widget import variables_input
from daras_ai_v2.utils import get_relative_time

DEFAULT_META_IMG = (
# Small
Expand Down Expand Up @@ -357,7 +358,11 @@ def render(self):
with gui.nav_item(url, active=tab == self.tab):
gui.html(tab.title)

if self.current_pr and not self.current_pr.is_root():
if (
self.current_pr
and not self.current_pr.is_root()
and self.tab == RecipeTabs.run
):
with gui.div(
className="container-margin-reset d-none d-md-block",
style=dict(
Expand Down
12 changes: 10 additions & 2 deletions daras_ai_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@

def get_relative_time(timestamp: datetime) -> str:
diff = timezone.now() - timestamp

if abs(diff) < timedelta(seconds=3):
return "Just now"

for threshold, unit in THRESHOLDS:
if diff >= threshold:
return f"{round(diff / threshold)}{unit} ago"
if abs(diff) >= threshold:
value = round(diff / threshold)
return (
f"{value}{unit} ago" if diff > timedelta() else f"in {abs(value)}{unit}"
)

return "Just now"

0 comments on commit 6573837

Please sign in to comment.