mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 22:15:14 +00:00
fix fuck ass timestamping
This commit is contained in:
parent
d0d8e387e3
commit
3f9e7b5a43
1 changed files with 8 additions and 3 deletions
|
|
@ -25,7 +25,12 @@ module Api
|
|||
def user_info
|
||||
user = find_user_by_id
|
||||
return unless user
|
||||
valid = user.heartbeats.where("time BETWEEN ? AND ?", Time.utc(2000, 1, 1).to_i, Time.utc(2100, 1, 1).to_i)
|
||||
valid = user.heartbeats.where("CASE WHEN time > 1000000000000 THEN time / 1000 ELSE time END BETWEEN ? AND ?", Time.utc(2000, 1, 1).to_i, Time.utc(2100, 1, 1).to_i)
|
||||
|
||||
lht = valid.maximum(:time)
|
||||
if lht && lht > 1000000000000
|
||||
lht = lht / 1000
|
||||
end
|
||||
|
||||
render json: {
|
||||
user: {
|
||||
|
|
@ -43,7 +48,7 @@ module Api
|
|||
banned: user.trust_level == "red",
|
||||
created_at: user.created_at,
|
||||
updated_at: user.updated_at,
|
||||
last_heartbeat_at: valid.maximum(:time),
|
||||
last_heartbeat_at: lht,
|
||||
email_addresses: user.email_addresses.map(&:email),
|
||||
api_keys_count: user.api_keys.count,
|
||||
stats: {
|
||||
|
|
@ -51,7 +56,7 @@ module Api
|
|||
total_coding_time: valid.duration_seconds || 0,
|
||||
languages_used: valid.distinct.pluck(:language).compact.count,
|
||||
projects_worked_on: valid.distinct.pluck(:project).compact.count,
|
||||
days_active: valid.distinct.count("DATE(to_timestamp(time))")
|
||||
days_active: valid.distinct.count("DATE(to_timestamp(CASE WHEN time > 1000000000000 THEN time / 1000 ELSE time END))")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue