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

Parse Timestamps in Messages: Core Implementation #5253

Closed
wants to merge 6 commits into from

Conversation

aero31aero
Copy link
Member

Code needs cleaning up as well as decisions regarding the display format.

Example: !timestamp(Jun 6 2017 4:48 PM) should render as <span class="timestamp" value="1496767680">Tuesday, June 6th 2017, 10:18:00 pm (Timezone: UTC+05:30)</span>.

Question: What should we do with timestamps that are incorrect or not parsable?
Currently, I've done it so that no error messages are displayed and the original text is kept intact.

Since right now the syntax only picks up timestamps in UTC, I'm looking for ways to add support for timezones using dateutil.parser.

Some sample runs:
image

@timabbott
Copy link
Sponsor Member

timabbott commented Jun 6, 2017

@aero31aero this is a great start! A few thoughts, looking at this:

  • For errors, I think we could follow the pattern of our LaTeX support and just show what entered with some coloring to show they did it wrong? The other option is to do nothing special.

  • Maybe we want this to be called !time, not !timestamp? That feels more user-friendly in retrospect.

  • Let's start adding tests to zerver/fixtures/bugdown-data.json to encode decisions like how to handle errors, etc.

  • Let's scope the CSS to inside a .message_content, since I can easily see us having a .timestamp in something.

  • For the format, I have a few thoughts. First, I think we don't need the Timezone:. And am/pm should be capitalized (assuming the user's specified display time format isn't military time; we should be using page_params.timezone and page_params.twenty_for_hour_time). Other than that,

<span class="timestamp" value="1496767680">Tuesday, June 6th 2017, 10:18:00 PM (UTC+05:30)</span>

looks pretty reasonable, though it'd be nice if we had a good way to not include the :00 seconds in the case that they're not needed.

@aero31aero
Copy link
Member Author

  1. I was thinking of using colors as well, and would give that a go. For regular correctly parsed values, I was thinking of a simple grey colored or similar highlight so that it doesn't feel obtrusive to the user.
    2/3/4: Okay.
  2. About parsing timezones. If users don't have timezone set in their profile, I'd revert to using the current system's timezone. Or, in those cases showing timezone would be useful, I guess.

Making the changes now.

@aero31aero
Copy link
Member Author

aero31aero commented Jun 7, 2017

24 Hours time:
image
12 Hours time:
image
@timabbott this seems fine?
Edit: Ignore the blue highlight in first case. That's just Firefox Dev Tools.

@aero31aero aero31aero force-pushed the timedown branch 2 times, most recently from 6570ff1 to 993a1b9 Compare June 7, 2017 18:29
@aero31aero
Copy link
Member Author

Squashed all commits. If you could review this fast and probably have it merged before the next round of meetings, that could give the feedback required for making changes I suppose.
TODO: Add support for specifying time in time zones other than UTC. Would add a commit when I get it working.

@timabbott
Copy link
Sponsor Member

Hmm, I think we do want the timestamp elements set apart, but I'm not sure the green color is the right way to do that. @brockwhittaker @jackrzhang any ideas what we should use there?

@brockwhittaker
Copy link
Collaborator

I would get rid of the "hrs". If you're on 24-hour time, you don't need anything after. I would also change "not a good time" to "Invalid Date", since that's more standard.

The new color you've changed it to here looks good. You have a padding-right: 4px but you should also add the same padding on the left; the clock is too close to the edge. I'd also then add some padding between the text and the clock.

screen shot 2017-06-12 at 4 55 27 pm

Otherwise looks good now!

@aero31aero aero31aero force-pushed the timedown branch 2 times, most recently from 9cda4c2 to c6e434d Compare June 14, 2017 00:49
@aero31aero
Copy link
Member Author

I've made the changes @brockwhittaker . Also, the default is to show the text that the user entered, and not a good time was just my trial text. Sorry for the confusion. Here is the updated screenshot:
image
I'll try to integrate a timepicker with this UI in the composebox now..

@lonerz
Copy link
Member

lonerz commented Jun 14, 2017

Seems like Case 5 still says "not a good time" :)

@aero31aero
Copy link
Member Author

Guess I did really choose a bad sample string...
@lonerz see this one. Sorry for the confusion.
image

@timabbott
Copy link
Sponsor Member

timabbott commented Jun 14, 2017

@aero31aero it looks like you haven't updated the markdown docs? There's 2 copies, a short-form in-app version and a long-form /help/ version.

While you're at it, would you be up for updating docs/markdown.md to make clear any changes need to be documented (in its own commit)? Thanks!

@timabbott
Copy link
Sponsor Member

A few more thoughts:

  • I think we should use "AM", not "am", for consistency with what we do elsewhere in Zulip.
  • Maybe we should make the styling look more similar to mentions visually?

image

"input": "!time(hello world)",
"expected_output": "<p><span class=\"timestamp\"><img alt=\":clock4:\" class=\"emoji\" src=\"/static/generated/emoji/images/emoji/unicode/1f553.png\" title=\":clock4:\"><span>hello world</span></span></p>",
"bugdown_matches_marked": false
},
Copy link
Sponsor Member

@timabbott timabbott Jun 14, 2017

Choose a reason for hiding this comment

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

why does bugdown not match marked for these? I think that's probably a sign that the frontend implementation is buggy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was of the opinion that if there are any differences in what can be parsed and what cannot be, that would cause ambiguity. Worst case, someone would immediately see something as having been parsed but later realize that it actually wasn't. So, we should have that logic in one place only.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Well, these are the tests for the markdown processor; at least the specific examples we wrote tests for should match, right?

(Also, we should have both a unix timestamp and full date test cases, right?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, those examples should. I was still trying to get the UI passed, though. I'll add more tests and make the marked implementation pass them as well.

@timabbott
Copy link
Sponsor Member

@aero31aero this one feels pretty close to completion; do you time to get it into a mergable state? I'd love to have this feature :)

@aero31aero
Copy link
Member Author

There are minor display ideas from Rishi's comment that could be implemented, but this should be good for a trial run on CZO.

Maybe we can iterate with minor changes on top of this in a later PR.

static/js/timerender.js Outdated Show resolved Hide resolved
static/js/timerender.js Outdated Show resolved Hide resolved
@timabbott
Copy link
Sponsor Member

Posted comments on the timerender commit; I think with a few fixes we can merge that piece at least.

static/js/markdown.js Outdated Show resolved Hide resolved
Comment on lines +170 to +174
let timestring = time.format('ddd, MMM D');
if (now.year() !== time.year()) {
timestring += time.format(' YYYY');
}
timestring += ',';
Copy link
Member

Choose a reason for hiding this comment

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

This kind of code is going to be tricky to localize. Moment has a fairly comprehensive collection of auto-localizing formatting codes, can we just use those?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Yeah, I'd love to use something from moment rather than this big block of code if there's something appropriate.

@aero31aero
Copy link
Member Author

Tests are passing. I wrote a small TODO list for the work left in https://chat.zulip.org/#narrow/stream/6-frontend/topic/timestamp, which is all just frontend related work and the html syntax is final.

This PR has gone on for too long, I'll work on those frontend TODOs in a new one.

@timabbott
Copy link
Sponsor Member

Can you move the cleanup commits that aren't part of this feature to the start of the branch, with proper commit messages? E.g. the tab_list commit doesn't explain the problem it solves or why it doesn't break something important to make that change.

@aero31aero
Copy link
Member Author

Pushed the cleanup commits to top and added more details in the top-bar CSS change commit.

@aero31aero
Copy link
Member Author

@timabbott do you have time to look at this?

This code generates the timestamp string to be shown to the user
from the given timestamp in unix format using moment.js.
We leverage the composebox typeaheads to show flatpickr to pick dates
and times for the !time syntax.
We use moment.js to try and parse the time from current token. If we
are successful, we init flatpickr with the parsed time, else we default
to using the current time.
We display stream descriptions in the tab-bar that is rendered
by our markdown pipeline, thus we have support for timestamps
in it. This commit adds the frontend bit where we replace the
raw timestamp with a human readable version.
This commit shifts our timestamp syntax to be of the form:

    <span class="timestamp data-timestamp="123456"></span>

since value is not a valid attribute of span elements.
@aero31aero
Copy link
Member Author

Finally, closing this in favor of the 3 individual PRs that have been split from this. 🎉

@aero31aero aero31aero closed this May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants