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

Undefined method `utc' for String #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlanLattimore
Copy link

Dependencies

PgSQL 12
ruby: 2.6.5
rails: 5.2.3
pg: 1.1.4
que: 1.0.0.beta4 (commit 065981)
que-web: HEAD (commit 3f7b7b7)

Reproduce Condition

Visit /que/scheduled

How System Behaves

  • System displays the message:
NoMethodError at /que/scheduled
undefined method `utc' for "2020-09-06 22:17:03":String
in que-web/lib/que/web.rb in relative_time:188
que-web/web/views/scheduled.erb:26

My best guess so far is que-web/lib/que/web.rb:39

scheduled_jobs = Que.execute SQL[:scheduled_jobs], [pager.page_size, pager.offset, search]

returns run_at as a string, example: "2020-09-06 22:17:03"

The relative_time helper expects a Time object at lib/que/web.rb:189

      def relative_time(time)
        %{<time class="timeago" datetime="#{time.utc.iso8601}">#{time.utc}</time>}
      end

and the String class is missing .utc

Notes:
I base this fix (loosely) on que-rb/que@87d40e7.

@@ -185,6 +185,7 @@ def format_error(job)
end

def relative_time(time)
time = Time.utc((t = Date._parse(time))[:year], t[:mon], t[:mday], t[:hour], t[:min], t[:sec]) if time.is_a?(String)
Copy link
Owner

Choose a reason for hiding this comment

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

What about using Time::parse from stdlib for parsing to a time like your original proposal?

# Top of file
require 'time'


def relative_time(time)
  time = Time.parse(time) if time.is_a?(String)
  %{<time class="timeago" datetime="#{time.utc.iso8601}">#{time.utc}</time>}
end

Copy link
Author

Choose a reason for hiding this comment

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

Time.parse() parses using local time with the result that

time = '2020-09-06 22:17:03'
relative_time(time)

returns <time class="timeago" datetime="2020-09-07T02:17:03Z">2020-09-07 02:17:03 UTC</time>
for my current timezone (EDT).

However, I believe run_at is not meant to be treated as local.

When I add a job with a run_at in utc (example 1.year.from_now.utc => Fri, 29 Oct 2021 20:43:40 UTC +00:00), run_at is returned as "2021-10-29 20:30:01.405839" using Que::Web::SQL[:scheduled_jobs]

When I add a job with run at in local time (example Time.now + 1.year => 2021-10-29 16:44:14 -0400), , run_at is returned as "2021-10-29 20:44:14.053852" again using Que::Web::SQL[:scheduled_jobs]

In my setup of Postgres, pg, Rails and que, I think run_at is returned as a string without timezone and is assumed to be in UTC, not local.

Copy link
Author

Choose a reason for hiding this comment

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

time = Time.use_zone('UTC') { Time.zone.parse time } if time.is_a?(String)

might be more expressive and clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants