Skip to content

Fix outdated regex in BQL interval() function#280

Open
mlell wants to merge 1 commit intobeancount:masterfrom
mlell:master
Open

Fix outdated regex in BQL interval() function#280
mlell wants to merge 1 commit intobeancount:masterfrom
mlell:master

Conversation

@mlell
Copy link
Copy Markdown

@mlell mlell commented May 11, 2026

The function pre-filtered the input string accepting only day, month, or year, while the function accepts more inputs. Change the regex to split only number from word.

Before:

beanquery> select distinct interval('1 week')
  interval('1 week')  
----------------------
                            <<<<<< empty, i.e. None is returned!
beanquery> select distinct interval('1 day')
  interval('1 day')   
----------------------
relativedelta(days=+1)

Now:

beanquery> select distinct interval('1 week')
  interval('1 week')  
----------------------
relativedelta(days=+7)

The function pre-filtered the input string accepting only day, month,
or year, while the function accepts more inputs. Change the regex to
split only number from word.
Comment thread beanquery/query_env.py
x = x.lower()
m = re.fullmatch(r'([-+]?[0-9]+)\s+([a-z]+?)s?', x)
if not m:
return None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insted of returning None, would it not be better to raise some kind of syntax error (e.g. 'cannot match interval string with any of of allowed ones... ')

Comment thread beanquery/query_env.py
if unit == 'millennium':
if unit in ['millennium', 'millenia']:
return relativedelta(years=number * 1000)
return None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insted of returning None, would it not be better to raise some kind of syntax error (e.g. 'cannot match interval string with any of of allowed ones... ')

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants