Resolve some time zone weirdness in date queries
I ran into some issues today when attempting to find some items by the specific day that they were added. Specifically, it looks like there is a mismatch between the time zones of the timestamps used for the query bounds and hose used for added dates in the database. My guess is that we need `fromtimestamp` where we have `utcfromtimestamp` or vice-versa.

Paging @silb, who might have a better idea of what to do here. (But depending on how close you live to UTC, you might not even have noticed!) I'll look into it also, but if you can figure out what needs to be fixed here, please go ahead and resolve.

diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py
index 318a7fbe2..be4172692 100644
--- a/beets/dbcore/query.py
+++ b/beets/dbcore/query.py
@@ -330,8 +330,15 @@ class FalseQuery(Query):
 
 
 def _to_epoch_time(date):
-    epoch = datetime.utcfromtimestamp(0)
-    return int((date - epoch).total_seconds())
+    epoch = datetime.fromtimestamp(0)
+    delta = date - epoch
+    try:
+        return int((delta).total_seconds())
+    except AttributeError:
+        # datetime.timedelta.total_seconds() is not available on Python 2.6
+        return int((delta.microseconds
+                    + (delta.seconds + delta.days * 24 * 3600) * 10 ** 6)
+                   / 10.0 ** 6)
 
 
 def _parse_periods(pattern):
@@ -454,7 +461,7 @@ class DateQuery(FieldQuery):
         date = datetime.utcfromtimestamp(timestamp)
         return self.interval.contains(date)
 
-    _clause_tmpl = "date({0}, 'unixepoch') {1} date(?, 'unixepoch')"
+    _clause_tmpl = "{0} {1} ?"
 
     def col_clause(self):
         clause_parts = []
@@ -474,5 +481,4 @@ class DateQuery(FieldQuery):
         else:
             # Match any date.
             clause = '1'
-
         return clause, subvals
['beets/dbcore/query.py']