Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wakatime compatible summaries API returns no data for start and end on the same day #192

Closed
devgianlu opened this issue Apr 29, 2021 · 3 comments
Labels
bug Something isn't working effort:1 prio a

Comments

@devgianlu
Copy link

devgianlu commented Apr 29, 2021

Requesting https://wakapi.dev/api/compat/wakatime/v1/users/current/summaries?start=2021-04-29&end=2021-04-29 returns:

{"data":[],"end":"0001-01-01T00:00:00Z","start":"2021-04-29T10:31:15.931236156+02:00"}

The official API will return one summary for the given day.

The problem definitely lies in this function:

wakapi/utils/date.go

Lines 70 to 83 in 331ace3

func SplitRangeByDays(from time.Time, to time.Time) [][]time.Time {
intervals := make([][]time.Time, 0)
for t1 := from; t1.Before(to); {
t2 := StartOfDay(t1).Add(24 * time.Hour)
if t2.After(to) {
t2 = to
}
intervals = append(intervals, []time.Time{t1, t2})
t1 = t2
}
return intervals
}

end is wrong probably because the list of summaries produced is empty and it's not updated, but it should fix itself with the above:

for i, s := range summaries {
data[i] = newDataFrom(s)
if s.FromTime.T().Before(minDate) {
minDate = s.FromTime.T()
}
if s.ToTime.T().After(maxDate) {
maxDate = s.ToTime.T()
}
}

This should also fix the CLI command --today used to show the status bar in IntelliJ IDEs (https://github.com/wakatime/wakatime/blob/e8deb156f1c2d26e5cf874da97f7b4354b3f5d20/wakatime/api.py#L165).

P.S. I am mainly pointing out where the problem is and not making PRs because I'd like to avoid setting up a development environment, but I might at some point to add some functionalities if you like.

@muety
Copy link
Owner

muety commented Apr 29, 2021

Thanks, I pushed an update that should have fixed the issue. Please check. However, we still do not have 100 % API compatibility with WakaTime, unfortunately. See #58.

This should also fix the CLI command --today used to show the status bar in IntelliJ IDEs

No, unfortunately, the CLI still has hard-coded API endpoints, to the plugins' status bars won't work until https://github.com/wakatime/wakatime/issues/260 is resolved.

@devgianlu
Copy link
Author

Definitely fixed, thanks.

The other endpoint needed for the app to work properly would be the user endpoint. Right now it's using a dummy user with everything empty. (I could have a look at that if I have time and make a PR as it should be pretty straightforward to do, let me know)

Other endpoints aren't required as they are optional features.

@muety
Copy link
Owner

muety commented Apr 29, 2021

The other endpoint needed for the app to work properly would be the user endpoint

I'll have a look tomorrow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working effort:1 prio a
Projects
None yet
Development

No branches or pull requests

2 participants