Skip to content
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

User-friendly date and time formatting. #1218

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

plugyawn
Copy link
Collaborator

@plugyawn plugyawn commented Apr 29, 2022

What does this PR do?
Adds user friendly times to the user and message info views. The current view just includes the timestamp, which is hard to decipher.

Partial fix for issues #1211 and addresses #1086

Tested?

  • Manually
  • Existing tests (adapted, if necessary)
  • New tests added (for any new behavior)
  • Passed linting & tests (each commit)

Commit flow

  • first commit adds a helper function to friendly-fy the timestamps.
  • second commit implements the helper function in views.py for message and user info popups.

Notes & Questions

Interactions

Visual changes
For message info:
Screenshot 2022-04-29 at 1 11 14 PM

For user info:
Screenshot 2022-04-29 at 1 11 01 PM

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Apr 29, 2022
@@ -1162,6 +1163,7 @@ def _fetch_user_data(controller: Any, user_id: int) -> Dict[str, Any]:
}
return display_data

pretty_date = user_friendly_time(data["last_active"])
Copy link
Collaborator

@mounilKshah mounilKshah May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For users who have been inactive for longer than two weeks, the data["last_active"] is empty. This is causing ZT to crash for such users when I tried running it.

@neiljp
Copy link
Collaborator

neiljp commented May 4, 2022

@plugyawn You saw my feedback in the stream, but essentially:

  • this is unstable right now, at least with the issue @mounilKshah pointed out, as well as for me
  • actual timestamps rather than formatted dates would likely be more reliable for comparison
  • tests would make it easier to provide potential buggy inputs and get them working
  • git commit style could be improved, as we discussed via gitlint.

@neiljp neiljp added enhancement New feature or request area: UI General user interface update PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels May 4, 2022
@plugyawn
Copy link
Collaborator Author

plugyawn commented May 5, 2022

@plugyawn You saw my feedback in the stream, but essentially:

  • this is unstable right now, at least with the issue @mounilKshah pointed out, as well as for me
  • actual timestamps rather than formatted dates would likely be more reliable for comparison
  • tests would make it easier to provide potential buggy inputs and get them working
  • git commit style could be improved, as we discussed via gitlint.

Sorry for the late reply!

  • @mounilKshah thanks for pointing out the error! I've fixed it.
  • Agreed, I'll check into that. In this case, though, do you think it'll make much of a difference?
  • On it! I'll get started with adding tests.
  • I set up gitlint, hopefully it's working now : )

@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels May 6, 2022
@plugyawn plugyawn force-pushed the 290422 branch 2 times, most recently from eefdc96 to 19d8477 Compare May 6, 2022 07:11
@plugyawn
Copy link
Collaborator Author

plugyawn commented May 6, 2022

@neiljp could you check the commit flow now?

@neiljp
Copy link
Collaborator

neiljp commented May 6, 2022

@plugyawn As per discussion in the stream, you really need a rebase (or other adjustment) since you seem to have squashed commits from upstream/main or another PR into one of these commits.

@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: XL [Automatic label added by zulipbot] labels May 11, 2022
datetime_object = datetime.strptime(
time_stamp, "%a %b %d %Y %I:%M:%S %p"
) # Fri Apr 29 2022 05:15:12 AM is an example
else: # for user_info, year not included
if time_stamp[-1] == "M": # AM or PM
else: # for user_info, year not included
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to keep these lint fixes in the commit in which they were introduced. If you do an interactive rebase and edit the previous commit and run make fix, then when you continue the rebase, these changes should likely drop out of this commit (or similarly in later commits, in other complex PRs).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay! Didn't know, I'll try it out.

@plugyawn plugyawn force-pushed the 290422 branch 9 times, most recently from e6afbdd to b89b8ab Compare June 5, 2022 02:51
@plugyawn
Copy link
Collaborator Author

plugyawn commented Jun 5, 2022

@mounilKshah @neiljp Could you check this now? I think the changes I made in test_popups.py need to be changed -- but I'm unsure as to what those changes should be.

Also, I've made sure the commits only contain changes in their respective files, as you said. Editing the commits and running commit --amend was the solution, as you said.

@plugyawn plugyawn added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jun 5, 2022
Copy link
Collaborator

@mounilKshah mounilKshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR works well, without any glitches and the commit structure is better than when I had last seen. I have left a few comments,

Also, maybe change the name of the branch on your forked repo? It can create confusion while working with multiple PRs.

@@ -816,3 +817,61 @@ def open_media(controller: Any, tool: str, media_path: str) -> None:

if error:
controller.report_error(error)


def user_friendly_time(time_stamp: str) -> str: # message_info has a different format
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of writing what the function does in the commit message, I think it would be more convenient to write it as comments within the function body, so that the next person working on it doesn't have to search for the respective commit(s).

if seconds < 86400: # 24 hours
return str(seconds // 3600) + " hours ago"

time_string = ""
Copy link
Collaborator

@mounilKshah mounilKshah Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of time_string is assigned only in the first conditional, but not returned/used anywhere.

@mounilKshah mounilKshah added the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jun 9, 2022
@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Jun 19, 2022
This commit adds a function that takes in a datetime string,
checks whether it came from message_info or user_info depending
on string length (later, we could include a boolean in the
arguments. For now, that's an unnecessary variable), and then
returns a user-friendly version of the date and time.

For example, if the string is
"Fri Apr 29 2022 05:15:12 AM", then converted will be something like
"A week ago", "43 minutes ago", and so on.
This commit implements the helper function for friendly times
to the user and message info pop-ups.

It shows up as
Fri 4 Apr 11:05:20 PM
(A week ago)

And so on.
@plugyawn
Copy link
Collaborator Author

plugyawn commented Aug 6, 2022

Reviews incorporated into the PR.

@plugyawn plugyawn added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Aug 6, 2022
@zulipbot
Copy link
Member

Heads up @plugyawn, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: UI General user interface update enhancement New feature or request has conflicts PR needs review PR requires feedback to proceed size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants