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

Start and end of day incorrect for timezone #117

Closed
johnhamilton opened this Issue Oct 15, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@johnhamilton

johnhamilton commented Oct 15, 2017

Problem description

When i start ActivityWatch it shows the wrong day not that current day as its recording today's data for the 15th but its the 16th in Australia and on my computer clock.

What i think the problem is

The code that is recording the the Activity is using a USA data and code showing the page is using the Australia data/my computers data.

@johnhamilton johnhamilton changed the title from When started show the data for the wrong day. to When started shows the data for the wrong day. Oct 15, 2017

@johnhamilton johnhamilton changed the title from When started shows the data for the wrong day. to When started shows and records the data wrong day. Oct 15, 2017

@johnhamilton

This comment has been minimized.

johnhamilton commented Oct 16, 2017

Seams to change to the next day at Lunch/Midday it should be switched to midnight maybe?

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 16, 2017

Definitely! I thought we had fixed this, but apparently, it persists.

The data is likely logged correctly (we store everything in UTC). It's just the web UI that doesn't query the data correctly (for whatever reason doesn't take into account your timezone). I'll take a look at this.

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 16, 2017

I think I fixed this issue here: ActivityWatch/aw-webui#49

It'll be included in the next release, thanks for reporting! 😄

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 23, 2017

I'm closing this, please let me know if the new release fixed it for you @johnhamilton!

@ErikBjare ErikBjare closed this Oct 23, 2017

@ErikBjare ErikBjare reopened this Oct 27, 2017

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 27, 2017

This was not fixed. I did some digging and we seem to have slightly deeper problems, but a fix should be easy.

Example code:

from datetime import datetime, timezone, timedelta
import aw_client

api = aw_client.ActivityWatchClient(testing=True)
buckets = api.get_buckets()

window_bid = next(bid for bid in buckets.keys() if "window" in bid and "testing" not in bid)
print(window_bid)

utcplus2h = timezone(timedelta(hours=2))
start = datetime(year=2017, month=10, day=27, hour=0, tzinfo=utcplus2h)
end = start + timedelta(hours=24)

events = api.get_events(window_bid, start=start, end=end, limit=-1)
print(len(events))
print(events[0].timestamp)
print(events[-1].timestamp)

Output:

aw-watcher-window_erb-main2-arch
8080
2017-10-27 13:26:10.608000+00:00
2017-10-27 00:09:23.451000+00:00

This output is wrong since the first event should not be from 00:09 UTC, but rather from right after 22:00 UTC. I suspect we are missing a dt.astimezone(timezone.utc) somewhere in the datastore layer.

  • Write test that ensures timezones behave correctly
  • Write a fix

@ErikBjare ErikBjare changed the title from When started shows and records the data wrong day. to Start and end of day incorrect for Australian timezone Oct 27, 2017

@ErikBjare ErikBjare changed the title from Start and end of day incorrect for Australian timezone to Start and end of day incorrect for timezone Oct 27, 2017

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 27, 2017

Alright, found the issue and implemented a fix: ActivityWatch/aw-core@b57564c

Now we just need to write a datastore tests to ensure it doesn't happen again.

@ErikBjare

This comment has been minimized.

Member

ErikBjare commented Oct 27, 2017

Wrote a test here: ActivityWatch/aw-core@4b89faf

Works great now, closing.

@ErikBjare ErikBjare closed this Oct 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment