-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Date queries for a single day do not return tracks within the final hour of that day #2652
Comments
Well! That's very tricky—thank you for investigating this. In my experience, time- and time-zone-related bugs can be among the most monstrous. I think you're right to be suspicious of that FWIW, in my time zone (US Eastern), here's what that epoch returns:
|
I'll try that, thanks. It might be that we need to consolidate all methods of calculating times into a single helper function. So this is interesting - for a few years (including the year of 1970) the UK ran an experiment where the timezone was GMT +01:00 for the whole year round - which might explain why the epoch in my timezone is 1am. https://en.wikipedia.org/wiki/British_Summer_Time#Periods_of_deviation There's some further discussion on this from a Python point of view here: https://stackoverflow.com/questions/40332018/python-able-to-handle-timestamps-timezone-insensitively-except-in-gmt Timezones in Python are definitely something I want to understand fully, so I'd be happy to take this on. One approach I've seen used is that you always store timestamps in UTC, and you only convert them to local time on output (e.g. displaying The downside to storing in UTC could be that we then lose the context of the local time of that particular datetime. It perhaps doesn't matter so much when it comes to I think you can save the timezone in a ISO datetime string by appending e.g. |
Got it; thanks for looking into it! Your points about keeping local time information are well taken. I think it makes the most sense to (try to) align everything to UTC for now, since that seems to be the most universal. I like the idea of augmenting this with TZ information down the road for the kinds of use cases you posted out. |
Some good news - we are probably already storing We are using
...and, on most systems, I think the problem may stem from where we try to convert a date for a query into a timestamp, and the clue is in the docstring:
...so we're converting to a local timestamp, when I think we should be converting to a UTC timestamp. In my timezone (GMT) this has the small but noticeable effect of my queries being 1 hour out (and in fact this gets cancelled out during the summertime BST). However, in other timezones it would have a much larger effect. Hence, I'm wondering why this bug hasn't been noticed before now? I would like to make sure this is a problem for everyone and not just me, before I start changing the code. @sampsyo (or indeed anyone not in GMT/BST) - could you try to recreate the issue from your timezone, by attempting to query (by date added) some tracks that you know were added in a specific hour, and see if you get back the expected results? |
FWIW, this started happening to me just after midnight
but only in the Python 2.7 tox environment, not for Python 3.6. Clock is CEST. (tbh, I didn't read the full thread, I just remembered having seen this when the error popped up) |
Happy new year! Looks like this same problem just triggered some test problems because we're within a few hours of a new month. See on Travis, for example: The specific problem uncovered here is that, in
|
Hi Adrian, happy new year! How dedicated of you to be watching the builds over NYE :) I'm afraid I put this problem on the backburner as I needed to spend more time with my actual music rather than the code! Also it was making my head spin... I will try to come back to it at some point, but if anyone wants to pick this up in the meantime (no pun intended), feel free. |
Sounds good. It's hard to blame you for focusing on music itself rather than hacking about music. 😃 |
OK; I've finally committed the above-mentioned change to I convinced myself that this was the right fix using two facts. First, an observation that: >>> datetime.datetime.fromtimestamp(time.time()) returns a datetime tuple that actually reflects what I think of as the current time. (The Whew! Time zone stuff is rough. 😅 |
Problem
Date queries for a single day do not return tracks within the final hour of that day, e.g.
What's interesting is that if I print out the SQL clause that is being run, I get this:
And if I feed those timestamps into a timestamp-to-datetime converter, I get these dates:
February 13, 2017 11:00:00 PM GMT+00:00
February 14, 2017 11:00:00 PM GMT+00:00
The period actually runs from 11pm to 11pm. This would explain why my query doesn't return tracks from the final hour of the day. Note: GMT/UTC and my local timezone are "the same" in February, so I don't think this is an issue of timezone conversion.
I've done some digging through the code, and the start and end dates of the query appear to be correct as they get passed between the various components of beets - however, one thing did catch my eye - the point at which beets converts a datetime into a timestamp that can be passed to the db in the query.:
https://github.com/beetbox/beets/blob/v1.4.5/beets/dbcore/query.py#L530-L532
If I print the
epoch
variable to the terminal, I see1970-01-01 01:00:00
. Shouldn't this be midnight, and not 1am? Is there something wrong here?I'll keep digging and working on a pull request, but any help would be much appreciated.
Setup
The text was updated successfully, but these errors were encountered: