Undefined method `utc' for String#83
Conversation
| 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) |
There was a problem hiding this comment.
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>}
endThere was a problem hiding this comment.
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.
There was a problem hiding this comment.
time = Time.use_zone('UTC') { Time.zone.parse time } if time.is_a?(String)
might be more expressive and clearer.
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/scheduledHow System Behaves
My best guess so far is que-web/lib/que/web.rb:39
returns
run_atas a string, example: "2020-09-06 22:17:03"The
relative_timehelper expects aTimeobject at lib/que/web.rb:189and the String class is missing
.utcNotes:
I base this fix (loosely) on que-rb/que@87d40e7.