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
full published\created dates in title attr. for comments and articles #1656
full published\created dates in title attr. for comments and articles #1656
Conversation
|
Hi, congrats for your first PR, well done!
I'm not completely sure but I don't think you can do it at present, because DEV does not store anywhere the user's timezone (hence you can't change the time zone of the date during server side rendering). Another way to do that would be to use JavaScript that's able to read the browser's timezone and change the time from there. Both things seems outside the scope of the issue and this PR though :) |
|
Thanks @rhymes! That's what I figured. I couldn't see any signs of the usual timezone handling code, so I assumed it wasn't being done. Should I add "UTC" to the title value, so the viewer at least knows that the time they're seeing is in UTC? |
That's a good idea! Otherwise I might assume the time is in my timezone instead of UTC |
|
The build is currently failing with this error |
app/models/article.rb
Outdated
| @@ -342,6 +342,11 @@ def tag_keywords_for_search | |||
| tags.pluck(:keywords_for_search).join | |||
| end | |||
|
|
|||
| def long_publish_time | |||
| relevant_date = crossposted_at.present? ? crossposted_at : published_at | |||
| relevant_date.strftime("%e %B %Y at %I:%M%p %Z") | |||
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.
relevant_date can be nil
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.
Thanks, resolved by adding safe navigation: relevant_date&.strftime("%e %B %Y at %I:%M%p %Z")
app/models/comment.rb
Outdated
| @@ -166,6 +166,10 @@ def video | |||
| nil | |||
| end | |||
|
|
|||
| def long_publish_time | |||
| created_at.strftime("%e %B %Y at %I:%M%p %Z") | |||
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.
created_at can be nil if the comment has not been saved to the DB yet
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.
Thanks, resolved by adding safe navigation: created_at&.strftime("%e %B %Y at %I:%M%p %Z")
app/models/article.rb
Outdated
| @@ -342,6 +342,11 @@ def tag_keywords_for_search | |||
| tags.pluck(:keywords_for_search).join | |||
| end | |||
|
|
|||
| def long_publish_time | |||
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 would use a past tense here. The normal times are all crossposted_at, published_at, updated_at and so on.
So maybe something like full_published_at or long_published_at, something like that.
I also wonder if this and the other method in Comment shouldn't be in their respective decorators: article_decorator.rb and comment_decorator.rb -
I say this because it feels like just presentation logic, not really part of the business logic.
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 following the example set by readable_publish_date, which lives in both the Comment and Article models, but I agree a decorator makes more sense for both of them. I don't think moving the existing readable_publish_date methods should be part of this PR, but I will move my new methods into decorators. There don't seem to be any specs for decorators, should there be?
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.
Hmmm I know where @rhymes is going with this but I feel like the ..._at protocol like created_at, updated_at should possibly be reserved for values which are a raw timestamp where any time can be calculated from.
Where this might be better the case for a different naming convention. I'd guess that was the original logic at least. However, that isn't to say the current convention which @acflint was following is the correct one.
Yeah, decorator makes sense. We don't have current specs there. We definitely could. Decorator code is typically decently well-covered by request specs, but unit tests couldn't hurt!
Co-Authored-By: acflint <acflint@users.noreply.github.com>
|
This would be a good use of I18n's Date/Time format feature. You could implement that with the following: In en:
time:
formats:
long: "%e %B, %Y at %I:%M%p %Z"Remove Add this to def published_at
crossposted_at.presence || super
endThen <%= l(article.decorate.published_at, format: :long) %>
<%= l(comment.published_at, format: :long) %> |
|
Thank you for this PR @acflint ! Sorry we didn't get to this sooner. @rhymes took your PR as an inspiration and made it compatible with user's local time (#1970). If you could resolve the merge conflict, i'm happy to accept your share of work for the article's portion. Or i'm happy take over this PR if you'd like. |
|
I'm sorry to have to close your first PR on DEV 😔, but it's been sitting around for bit now. Superseded by #2722 |
What type of PR is this? (check all applicable)
Description
Adding
titleattributes to Commentcreated_atand Articlepublished_atelements displaying the full time\date.It's currently displaying in UTC, and I don't see in the code base how you deal with time zones to ensure times\dates are displayed in the user's correct zone. That would be a nice next step for this feature.
Related Tickets & Documents
#406
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
When you hover over the published date: https://www.dropbox.com/s/0fyqvf7up63a2u5/Screenshot%202019-01-27%2015.11.39.png?dl=0
When you hover over the created date: https://www.dropbox.com/s/aeryrw8hvu0knz9/Screenshot%202019-01-27%2015.11.48.png?dl=0
Added to documentation?
[optional] What gif best describes this PR or how it makes you feel?
It's my first pull request for Dev, so...
