ymdatta / pagure

Forked from pagure 6 years ago
Clone

f99ac7c Adjust activity heatmap and logs for timezone (#1642)

Authored and Committed by adamwill 6 years ago
    Adjust activity heatmap and logs for timezone (#1642)
    
    As discussed in #1642, there is a problem with the user activity
    log page in the web UI caused by a timezone mismatch. The
    library used to generate the heatmap assumes any date / time you
    feed it is in the browser timezone. Pagure ultimately feeds it
    the 'date' value of PagureLog instances, converted to a Unix
    timestamp. This timestamp reflects 00:00 on the date in question
    in the UTC timezone. If the browser timezone is behind UTC, the
    heatmap library treats the event as falling on the *previous*
    day, because in the browser timezone, that precise time falls on
    the previous day.
    
    It would be relatively easy to 'fix' this if all we wanted to do
    was have the heatmap reflect what date each event occurred on in
    the UTC timezone, as the activity log currently does. However, I
    don't think that's the best fix. I think the best behaviour here
    is for both the heatmap and the activity log to be relative to
    the browser timezone. As a Pagure user in a timezone several
    hours behind UTC, if I make a commit in the late afternoon of
    Wednesday, I'd expect the heatmap and the activity log to show
    that commit as occuring on Wednesday, not Thursday.
    
    So, this commit dumps the use of the 'date' value in this code,
    and works with the 'date_created' value instead, which is a
    precise UTC date and time (as opposed to just the date relative
    to UTC). We allow a timezone offset to be passed to the relevant
    methods, and figure out what date the events fell on *if that
    offset is applied*, rather than just what date they fell on in
    the UTC timezone. To facilitate this we add a custom method to
    the database model, `date_offset`, which gives the date when an
    arbitrary offset (in minutes, positive or negative) is applied.
    We tweak the relevant functions in pagure.lib to get all the
    necessary data from the database, then use the `date_offset`
    method to adjust and refine the results before returning.
    
    Fixes https://pagure.io/pagure/issue/1642
    
        
file modified
+7 -2
file modified
+44 -15
file modified
+9 -0