Skip to content

Commit

Permalink
Use dateutil.parser directly
Browse files Browse the repository at this point in the history
Remove indirection via beancount.utils.date_utils. This makes the
dependency on python-dateutil explicit and will allow to remove the
utility code from Beancount.

The one argument form of the parse_date() BQL function that tries to
guess the date format does not seem a great idea as the format used
for the conversion depends on the input string, thus it could
interpret different rows differently. It should be deprecated and
eventually removed.
  • Loading branch information
dnicolodi committed Sep 18, 2023
1 parent dfb6d6f commit daf09e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions beanquery/query_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from functools import lru_cache as cache
from decimal import Decimal

import dateutil.parser

from beancount.core.number import ZERO
from beancount.core.compare import hash_entry
from beancount.core import amount
Expand All @@ -29,7 +31,6 @@
from beancount.core import prices
from beancount.ops import summarize
from beancount.parser import options as opts
from beancount.utils.date_utils import parse_date_liberally

from beanquery import query_compile
from beanquery import tables
Expand Down Expand Up @@ -554,7 +555,7 @@ def possign(context, x, account):
def parse_date(string, frmt=None):
"""Parse date from string."""
if frmt is None:
return parse_date_liberally(string)
return dateutil.parser.parse(string).date()
return datetime.datetime.strptime(string, frmt).date()


Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ packages = find:
install_requires =
beancount >=2.3.4
click >7.0
python-dateutil >=2.6.0
tatsu >=5.7.4, <5.8.0
python_requires = >=3.8

Expand Down

0 comments on commit daf09e3

Please sign in to comment.