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

Admin Analytic's Work Reports renders in error when attempting to call strftime on a String. #5818

Open
jeremyf opened this issue Aug 26, 2022 · 0 comments

Comments

@jeremyf
Copy link
Contributor

jeremyf commented Aug 26, 2022

In app/views/hyrax/admin/analytics/work_reports/show.html.erb we have cases where @document.date_uploaded is not a Date-like object. When that view attempts to call strftime on the @document.date_uploaded we get the following error: undefined method strftime' for "2022-08-10T23:22:45Z":String.

Throughout the code base the @document.date_uploaded is rendered directly (e.g. no conversion). In the Hyrax::StatsUsagePresenter object we do ensure a date like value. Which indicates that this field cannot predicatably be called a Date.

Proposal: Add a helper method cast_to_formatted_date(value, format: "%Y-%m-%d") this would attempt to parse the value from String to date then render with the given format. Port this to the 3.4.x and 4.0.x branches.

jeremyf added a commit that referenced this issue Aug 29, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Aug 30, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Aug 30, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Aug 31, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Sep 1, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Sep 1, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Sep 1, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Sep 1, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
jeremyf added a commit that referenced this issue Sep 2, 2022
Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
dlpierce pushed a commit that referenced this issue Sep 2, 2022
* Pessimistic handling of non-Date objects

Prior to this commit, the view was (rightly) assuming that the
`@document.date_uploaded` was a Date-like object (e.g. responded to
`strftime`).  However, in the wild, we encountered situations where the
field was a String (that was of the form "CCYY-MM-DD").

This change introduces a helper method to handle the type negotiation.
It also follows on the logic introduced in [Hyrax::StatsUsagePresenter][1].

Closes ##5818

This change should be back-ported to v3.4.x and v3.3.x

[1]:https://github.com/samvera/hyrax/blob/27d62a2338bd9e49f942e7e73829f91f2e8115eb/app/presenters/hyrax/stats_usage_presenter.rb#L38-L42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant