-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
@aero31aero this is a great start! A few thoughts, looking at this:
looks pretty reasonable, though it'd be nice if we had a good way to not include the |
Making the changes now. |
24 Hours time: |
6570ff1
to
993a1b9
Compare
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. |
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? |
3014030
to
b0481f7
Compare
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 Otherwise looks good now! |
9cda4c2
to
c6e434d
Compare
I've made the changes @brockwhittaker . Also, the default is to show the text that the user entered, and |
Seems like Case 5 still says "not a good time" :) |
Guess I did really choose a bad sample string... |
@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! |
zerver/fixtures/bugdown-data.json
Outdated
"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 | ||
}, |
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.
why does bugdown not match marked for these? I think that's probably a sign that the frontend implementation is buggy.
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.
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.
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.
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?)
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.
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.
@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 :) |
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. |
Posted comments on the |
let timestring = time.format('ddd, MMM D'); | ||
if (now.year() !== time.year()) { | ||
timestring += time.format(' YYYY'); | ||
} | ||
timestring += ','; |
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.
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?
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.
Yeah, I'd love to use something from moment
rather than this big block of code if there's something appropriate.
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. |
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 |
Pushed the cleanup commits to top and added more details in the top-bar CSS change commit. |
@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.
Finally, closing this in favor of the 3 individual PRs that have been split from this. 🎉 |
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: