mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-15 20:09:18 -05:00
Heatmap: Actions are shown on the previous day #2920
Closed
opened 2025-11-02 04:54:05 -06:00 by GiteaMirror
·
20 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16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0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#2920
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @siddweiker on GitHub (Feb 15, 2019).
dfad5691.7.1 (docker image)Description
Heatmap actions are shown on the previous day for actions in an EST (and beyond?) timezone.
Steps to reproduce:
Screenshots
Here is a screenshot from my own gitea instance, the heatmap should show actions from Monday to Friday, instead they are shifted back one day.

From try.gitea.io, here is a combined screenshot to show the commit time and the heatmap action time:

@troygeiger commented on GitHub (Mar 5, 2019):
I noticed this today as well.
@Jamozed commented on GitHub (Mar 30, 2019):
NZST timezone (UTC +12:00/13:00) also does this, except only before midday.
@kolaente commented on GitHub (Apr 9, 2019):
This probably has to do with the fact the server runs in a different timezone (most likely utc) than your browser.
@Jamozed commented on GitHub (Apr 10, 2019):
This was the first thing I checked in my case, my server and browser are absolutely running in the same timezone.
@siddweiker commented on GitHub (Apr 10, 2019):
I think its because the time is striped from the timestamp.
c42bde719e/models/user_heatmap.go (L25)@stale[bot] commented on GitHub (Jun 9, 2019):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
@Brayyy commented on GitHub (Dec 29, 2020):
This issue is still present on 1.14.0+dev-394-g069acf6a2.
It is caused by a disparity in the timezone of the DB (MySQL in my case), and the local browser. My company mainly works out of the EDT timezone, but I am in PST (three hours behind). When I push code, I always see it appear on the prior day, however, if I adjust my local system time to be EDT, the blocks align correctly.
As noted, the issue is rooted in the DB query rounding
created_unixdown to the local day, then in the browser, JS applies the TZ offset, and then rounds this value down a second time, which is now the prior day.The best solution would likely be to read the timezone from the user browser and use that when globbing the
created_unixhours into a single day.@Colin5887 commented on GitHub (Jan 9, 2021):
@Brayyy
I think there are two problems: incorrect heatmap and incorrect commission time.
The commission time (the text popup when hovering on the "19 hours ago") can be changed by putting a
timesection in the setting. Everyone who accesses that gitea server will use the same time zone.However, the heatmap uses UTC+0 time zone and there is currently no way to change that. I live in AEDT (UTC+10) and every commission before 10:00 will be marked as yesterday's work.
@Colin5887 commented on GitHub (Jan 9, 2021):
@siddweiker
The heatmap uses UTC+0 time zone and cannot be changed by any settings (so far). The only way you can make a commission today is to push your work after 19:00 (since you live in UTC-5).
@kins-dev commented on GitHub (Feb 25, 2021):
I think you have that backwards.
I'm using PST (UTC -8). If I push at 1:00 AM, that is 9 AM UTC+0 of the same day.
https://www.google.com/search?q=1%3A00+AM+PST+to+UTC
If I push at 5 PM (17:00) then that should be shown as 1:00 AM on the next day if the heat map is UTC based.
https://www.google.com/search?q=17%3A00+PST+to+UTC
It should never show up on the previous day if the user has a negative offset to UTC. The heat map is just wrong.
Edit:
It appears this is a result of the timestamp in heatmap.json, being converted from UTC to the local time zone. For example If I have:
1614211200 represents Thursday, February 25, 2021 12:00:00 AM UTC
https://www.epochconverter.com/
If my browser then takes that as UTC and converts it to local time, that's Wednesday, February 24, 2021 4:00:00 PM UTC-08:00
So the timestamp being generated for grouping is causing the issue.
One possible way to fix this would be to go to:
https://github.com/go-gitea/gitea/blob/4172b1955fabe79e5918145f4ad1b00911390de0/web_src/js/features/heatmap.js#L11
use this instead:
I haven't actually tested out this change, but based on the JSON data and using my javascript console this should work.
@siddweiker commented on GitHub (Feb 25, 2021):
@kins-dev That will not work;
Given a user who is in the EST timezone:
16121412002021-02-01 01:00:00+00:002021-01-31 20:00:00-05:0016121376002021-02-01 00:00:00+00:002021-01-31 19:00:00-05:002021-02-01 00:00:00-05:002021-01-31 00:00:00-05:00The opposite happens for
1612306800(2021-02-02 18:00:00-05:00), the JS will be the previous day but your JS will be correct.The server is not aware of the client's timezone, so when it strips out the time, you will get shifted results on the client side.
The SQL should not group at all, and it should be done in heatmap.js.
A better solution would be to group to the hour in SQL, then have the JS convert it to local date (strip the time) and summarize it once more. This will send one timestamp per hour instead of every commit's timestamp.
@kins-dev commented on GitHub (Feb 26, 2021):
Really? Did you try it? Did you understand the issue? (The calendar.vue is running in the context of local time, for showing days but the server is providing the date via epoch which evaluates to the previous day when your timezone is behind UTC. You can think of it as taking the time specified and doing dropping the time information but keeping the date information. Using epoch time implies that time is in the UTC zone, so that information is not being stripped when it goes to your browser.)
So, I'm PST, but this will work for EST or any other timezone.
I made a brand new server and commits today, the result was as I stated before:
That's not February 25th where my browser or server is running. It is February 25th UTC time, in fact the very first moment of it. February 25th started at 1614240000 for the PST time zone.
So, doing the math 1614240000 - 1614211200 = 28800 seconds.
28800 seconds is 480 minutes which is 8 hours. Given that PST is GMT -8, that makes sense. (We're 8 hours behind GMT.)
Well what is:
https://jsfiddle.net/3v578s1r/1/
Does that match 1614240000?
I think it does, and in fact after putting my code in place, I get this now:

This is not perfect, far from it, but it is at least defensible. I'm using math to make the calendar.vue work based on UTC time so it matches the server in terms of what constitutes a single day. Why do you believe that won't work?
Edit:

That picture is a little hard to read, but you can see it says my account joined today. Here's the heatmap without the popup.
Before my change, those contributions all showed up the previous day in the heatmap
Edit 2: some wording.
Edit 3: Just realized it is just after midnight UTC, so I made a few more commits:

You can see the commits that should be attributed to 2/26/2021 are not shown here.
The heatmap data is now:
12 + 3 = 15 contributions and it is obvious the 3 are connected to the next day.
heatmap.vue and calendar.vue will not show the next day until it hits the 26th local time, so for now that data is not visible. Like I said not perfect, but better than putting items on the wrong day.
@kins-dev commented on GitHub (Feb 27, 2021):
So I believe the heat map end date can be fixed by:
50208e903a/web_src/js/components/ActivityHeatmap.vue (L38)to
And this should keep the heatmap in UTC.
I won't be able to test it for another day.
Of course this all could have been avoided if
c42bde719e/models/user_heatmap.go (L19)had kept the date string as a string instead of converting it seconds then milliseconds. (As per the documentation here: https://github.com/julienr114/vue-calendar-heatmap) We'd still need to play games with the end date.
That all said there's a better solution.
I want to make sure that someone like @lafriks, @kolaente, or @jolheiser see's this part: since my suggestion probably needs to be evaluated as part of the whole design.
if the function in user_heatmap.go was simplified to: (Remember to remove the unused reference)
So that everything is just grouped by their unix timestamp.
Then in heatmap.js if you did something like:
Then the heatmap would just work in the web browser's time zone and this entire issue would just go away.
Also it reduces the computational load on the server, by making clients sum the number of actions per day, The draw back is, it does increase the amount of data being sent between the client and the server. This may be a problem with a lot of commits, so the person fixing this might want to group by minute, or by a 10 minute interval, but I'll leave that up to them. (The original reason for grouping was not in a comment in the code, so I don't know if there's something I'm missing.)
@siddweiker commented on GitHub (Feb 27, 2021):
I'm in agreement. (This is what I proposed in my previous comment...)
There are 30min and 45min timezones (India is UTC +5:30). So grouping by date and 15 min intervals will give you the most accurate times with the least amount of data sent.
@Colin5887 commented on GitHub (Feb 27, 2021):
I'm tired of making no contributions every Friday and work overtime every Sunday. Hope this issue can be fixed soon.
BTW, Australian Central Daylight Time (ADST) is a +10.5 time. 15 minutes' interval is a great suggestion.
@siddweiker commented on GitHub (Feb 27, 2021):
I started working on a fix for the SQL and used the javascript fix from @kins-dev. SQLite seems to be working so far.
I also created a python script for testing while I work on it since I wanted to test every 15 minute time for an entire day.
@kins-dev commented on GitHub (Feb 27, 2021):
@siddweiker if you want to go that route you should be able to do some simple math in the SQL
Something like:
Probably need that in the select as well.
Since leap seconds are ignored by epoch time, this should just work for everyone.
Edit:
Oh and don't forget to multiply by 900 in the javascript
@kins-dev commented on GitHub (Feb 28, 2021):
@siddweiker
Okay so with 15 minute intervals the code is:
83cf1a894e/models/user_heatmap.go (L28-L72)83cf1a894e/web_src/js/features/heatmap.js (L5-L23)Note: In my previous code, I missed the 24 in the calculation of 53 weeks for the
user_heatmap.gofile. Oh and do remove the unneeded reference.I verified the results by looking at the contents of
div id="user-heatmap" data-heatmap-dataof the root html file:One second grouping:
15 Minute Grouping:
You can put that data into a spreadsheet if you want to confirm, there are multiple commits in the same 15 minute window, and commits that fall into sequential 15 minute windows.
I haven't tested anything but SQLite3
@kins-dev commented on GitHub (Mar 2, 2021):
Due to segfaults on the master branch when using issue management on the Arm64 platform, I'm going back to 1.13.2.
Back porting these changes:
014313134f/web_src/js/components/ActivityHeatmap.vue (L50-L60)becomes:
014313134f/models/user_heatmap.go (L18-L58)becomes:
There's a couple of bonuses here, one is the API should work the same again (no change in semantics) and the javascript code was cleaned up some.
@siddweiker commented on GitHub (Apr 6, 2021):
@kins-dev @Colin5887
I have a PR open if you want to test my changes.