oxidized-web icon indicating copy to clipboard operation
oxidized-web copied to clipboard

Dates column on Versions page is incorrect

Open AbortRetryFail opened this issue 8 years ago • 4 comments

oxidized-web seems to ignore time zone offset when it calculates the Dates column on the Versions page.

My timezone is UTC-5 and it shows 8 hours 20 minutes on the Versions page where the time on the diff is 3 hours 20 minutes ago.

AbortRetryFail avatar Feb 20 '17 19:02 AbortRetryFail

Did you find what was causing the discrepancy? I'm running into the same thing on my new install. 'Last Update' column time on nodes page is correct, but the Dates column is using UTC and therefore off by several hours.

Speiker avatar Mar 16 '18 20:03 Speiker

I have the same problem.

fatman00 avatar Jul 27 '18 19:07 fatman00

I think that this snippet helps? It trivially works for me, but YMMV:

--- webapp.rb.bk	2019-07-30 14:25:28.672867445 -0400
+++ webapp.rb	2019-07-30 15:29:15.839800875 -0400
@@ -267,6 +267,7 @@
           unless date.include? '+'
             date.insert(21, '+')
           end
+          date.sub! ' -+', "-"
           date = DateTime.parse date
           now = DateTime.now.new_offset(0)
           t = ((now - date) * 24 * 60 * 60).to_i

I think the root problem is parsing the dates form Git is failing. The unchanged date string is, for example, 2019-07-30 15:10:39 -+0400. This is parsed into 2019-07-30T15:10:39+00:00, which is incorrect (note the +00:00 TZ offset).

A simple tweak to the string that is parsed seems to work, at least in for negative timezone offsets.

I think this bug goes way back to e1d3674e, and I'm not sure why the date.insert() code is there.

A better patch may be to just remove this code completely:

--- webapp.rb.bk	2019-07-30 14:25:28.672867445 -0400
+++ webapp.rb	2019-07-30 15:40:12.476061445 -0400
@@ -263,10 +263,6 @@
       # give the time enlapsed between now and a date
       def time_from_now date
         if date
-          # if the + is missing
-          unless date.include? '+'
-            date.insert(21, '+')
-          end
           date = DateTime.parse date
           now = DateTime.now.new_offset(0)
           t = ((now - date) * 24 * 60 * 60).to_i

hawson avatar Jul 30 '19 19:07 hawson

It may not be the prettiest way, but I noticed that in my case, the diff was in a +3 hours shift. So, after a couple trial and error attempt, I just subtracted "3” to the hh variable before the date return.

[root@localhost web]# pwd
/home/oxidized/.gem/ruby/gems/oxidized-web-0.13.1/lib/oxidized/web
[root@localhost web]# diff webapp.rb webapp.rb.bkp
277c277
<             date = "#{dd} days #{hh-3} hours ago"
---
>             date = "#{dd} days #{hh} hours ago"
279c279
<             date = "#{hh-3} hours #{mm} min ago"
---
>             date = "#{hh} hours #{mm} min ago"
[root@localhost web]#

This is the part of code I altered.

[root@localhost web]# vi webapp.rb
    263       # give the time enlapsed between now and a date
    264       def time_from_now date
    265         if date
    266           # if the + is missing
    267           unless date.include? '+'
    268             date.insert(21, '+')
    269           end
    270           date = DateTime.parse date
    271           now = DateTime.now.new_offset(0)
    272           t = ((now - date) * 24 * 60 * 60).to_i
    273           mm, ss = t.divmod(60)
    274           hh, mm = mm.divmod(60)
    275           dd, hh = hh.divmod(24)
    276           if dd.positive?
    277             date = "#{dd} days #{hh-3} hours ago"
    278           elsif hh.positive?
    279             date = "#{hh-3} hours #{mm} min ago"
    280           else
    281             date = "#{mm} min #{ss} sec ago"
    282           end
    283         end
    284         date
    285       end

I had just made a config change and instead of 0 hours, it was showing 3 hours.

Before

After the fix and restarting my service, it showed 0 hours.

After

I saw a couple of tutorials, and this was not a very common issue. Don't know what exactly is my trigger here, but that fix is kind of enough for me.

Hope to help future people with the same problem, and if anyone has a better suggestion, I'm all ears.

It's not dumb if it works :)