-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show last saved time #559
base: master
Are you sure you want to change the base?
show last saved time #559
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Added relative timestamp display functionality for published recipes, with a new utility function for human-readable time differences.
- Added
get_relative_time()
in/daras_ai_v2/utils.py
to convert timestamps into human-readable formats (e.g. "2h ago") - Implemented
_render_saved_timestamp()
in/daras_ai_v2/base.py
to display last saved time for non-root published runs - Added responsive styling to position timestamp to the right of navigation tabs
- Note: Time calculation has limitations around month/year boundaries and lacks input validation
💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
THRESHOLDS = [
(timedelta(days=365), "y"),
(timedelta(days=30), "mo"),
(timedelta(days=1), "d"),
(timedelta(hours=1), "h"),
(timedelta(minutes=1), "m"),
(timedelta(seconds=3), "s"),
]
def get_relative_time(timestamp: datetime) -> str:
diff = timezone.now() - timestamp
for threshold, unit in THRESHOLDS:
if diff >= threshold:
return f"{round(diff / threshold)}{unit} ago"
return "Just now" |
Updated @devxpy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
This PR refactors the get_relative_time()
utility function to improve code maintainability and readability while preserving its core functionality of displaying relative timestamps.
- Introduced
THRESHOLDS
constant list inutils.py
to replace nested if-statements with a more maintainable threshold-based approach - Added type hints to
get_relative_time(timestamp: datetime)
for better code clarity - Changed rounding behavior from
int()
toround()
for more natural time representations - Modified seconds threshold from 2 to 3 seconds for "Just now" display
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
if diff >= threshold: | ||
return f"{round(diff / threshold)}{unit} ago" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: using round() instead of int() could change behavior - e.g. 1.6 days will now show as 2d instead of 1d
Q/A checklist
You can visualize this using tuna:
To measure import time for a specific library:
To reduce import times, import libraries that take a long time inside the functions that use them instead of at the top of the file:
Legal Boilerplate
Look, I get it. The entity doing business as “Gooey.AI” and/or “Dara.network” was incorporated in the State of Delaware in 2020 as Dara Network Inc. and is gonna need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Dara Network Inc can use, modify, copy, and redistribute my contributions, under its choice of terms.