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

full published\created dates in title attr. for comments and articles #1656

Closed
wants to merge 4 commits into from
Closed

full published\created dates in title attr. for comments and articles #1656

wants to merge 4 commits into from

Conversation

acflint
Copy link

@acflint acflint commented Jan 27, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

Adding title attributes to Comment created_at and Article published_at elements 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?

  • docs.dev.to
  • readme
  • no documentation needed

[optional] What gif best describes this PR or how it makes you feel?

It's my first pull request for Dev, so...
nervous

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2019

CLA assistant check
All committers have signed the CLA.

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Jan 27, 2019
@rhymes
Copy link
Contributor

rhymes commented Jan 27, 2019

Hi, congrats for your first PR, well done!

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.

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 :)

@acflint
Copy link
Author

acflint commented Jan 27, 2019

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?

@rhymes
Copy link
Contributor

rhymes commented Jan 27, 2019

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

@Link2Twenty
Copy link
Contributor

The build is currently failing with this error

1) Using the editor Submitting an article fill out form and submit
     Failure/Error: relevant_date.strftime("%e %B %Y at %I:%M%p %Z")
     
     ActionView::Template::Error:
       undefined method `strftime' for nil:NilClass

@@ -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")
Copy link
Contributor

@rhymes rhymes Jan 28, 2019

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

Copy link
Author

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")

@@ -166,6 +166,10 @@ def video
nil
end

def long_publish_time
created_at.strftime("%e %B %Y at %I:%M%p %Z")
Copy link
Contributor

@rhymes rhymes Jan 28, 2019

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

Copy link
Author

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")

@@ -342,6 +342,11 @@ def tag_keywords_for_search
tags.pluck(:keywords_for_search).join
end

def long_publish_time
Copy link
Contributor

@rhymes rhymes Jan 28, 2019

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.

Copy link
Author

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?

Copy link
Contributor

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>
@abraham
Copy link
Contributor

abraham commented Jan 29, 2019

This would be a good use of I18n's Date/Time format feature. You could implement that with the following:

In config/locales/en.yml add

en:
  time:
    formats:
      long: "%e %B, %Y at %I:%M%p %Z"

Remove long_published_at from CommentDecorator and ArticleDecorator.

Add this to ArticleDecorator:

def published_at
  crossposted_at.presence || super
end

Then Articles and Comments could be rendered like this:

<%= l(article.decorate.published_at, format: :long) %>
<%= l(comment.published_at, format: :long) %>

@maestromac
Copy link
Member

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.

@maestromac
Copy link
Member

I'm sorry to have to close your first PR on DEV 😔, but it's been sitting around for bit now.

Superseded by #2722

@maestromac maestromac closed this May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: unreviewed bot applied label for PR's with no review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants