Skip to content

Commit f79da0a

Browse files
committed
Fix #93: task's "start_date" and "deadline" sometimes off by one day
1 parent 793d023 commit f79da0a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

things/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__copyright__ = "2021 Alexander Willner & Michael Belfrage"
55
__credits__ = ["Alexander Willner", "Michael Belfrage"]
66
__license__ = "Apache License 2.0"
7-
__version__ = "0.0.12"
7+
__version__ = "0.0.13"
88
__maintainer__ = ["Alexander Willner", "Michael Belfrage"]
99
__email__ = "[email protected]"
1010
__status__ = "Development"

things/database.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ def make_tasks_sql_query(where_predicate=None, order_predicate=None):
472472
where_predicate = where_predicate or "TRUE"
473473
order_predicate = order_predicate or 'TASK."index"'
474474

475+
# Note: see remark at `make_date_filter()` as for why the first
476+
# two `date()` statements have no "localtime" modifier.
475477
return f"""
476478
SELECT DISTINCT
477479
TASK.uuid,
@@ -519,8 +521,8 @@ def make_tasks_sql_query(where_predicate=None, order_predicate=None):
519521
CASE
520522
WHEN CHECKLIST_ITEM.uuid IS NOT NULL THEN 1
521523
END AS checklist,
522-
date(TASK.startDate, "unixepoch", "localtime") AS start_date,
523-
date(TASK.{DATE_DEADLINE}, "unixepoch", "localtime") AS deadline,
524+
date(TASK.startDate, "unixepoch") AS start_date,
525+
date(TASK.{DATE_DEADLINE}, "unixepoch") AS deadline,
524526
date(TASK.stopDate, "unixepoch", "localtime") AS "stop_date",
525527
datetime(TASK.{DATE_CREATED}, "unixepoch", "localtime") AS created,
526528
datetime(TASK.{DATE_MODIFIED}, "unixepoch", "localtime") AS modified,
@@ -648,14 +650,14 @@ def make_date_filter(date_column: str, value) -> str:
648650
649651
Examples
650652
--------
651-
>>> make_date_filter('start_date', True)
653+
>>> make_date_filter('startDate', True)
652654
'AND start_date IS NOT NULL'
653655
654-
>>> make_date_filter('start_date', False)
656+
>>> make_date_filter('startDate', False)
655657
'AND start_date IS NULL'
656658
657-
>>> make_date_filter('start_date', 'future')
658-
"AND date(start_date, 'unixepoch', 'localtime') > date('now', 'localtime')"
659+
>>> make_date_filter('startDate', 'future')
660+
"AND date(startDate, 'unixepoch') > date('now', 'localtime')"
659661
660662
>>> make_date_filter('created', None)
661663
''
@@ -669,7 +671,12 @@ def make_date_filter(date_column: str, value) -> str:
669671

670672
# compare `date_column` to now.
671673
validate("value", value, ["future", "past"])
672-
date = f"date({date_column}, 'unixepoch', 'localtime')"
674+
# Note: not using "localtime" modifier on `date()` since Things.app
675+
# seems to store `startDate` and `dueDate` as a 00:00 UTC datetime.
676+
# Morever, note that `stopDate` -- contrary to its name -- seems to
677+
# be stored as the full UTC datetime of when the task was "stopped".
678+
# See also: https://github.com/thingsapi/things.py/issues/93
679+
date = f"date({date_column}, 'unixepoch')"
673680
operator = ">" if value == "future" else "<="
674681
now = "date('now', 'localtime')"
675682

0 commit comments

Comments
 (0)