Skip to content

Commit

Permalink
Make date a structured type
Browse files Browse the repository at this point in the history
This introduces a convening way to access the year, month, and day
parts of date objects, making the year(), month(), and day()
functions, and the homonym columns of the postings and entries tables
redundant. These will be deprecated and eventually removed.
  • Loading branch information
dnicolodi committed Feb 1, 2025
1 parent 74bd6cc commit 0aa0689
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions beanquery/query_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,27 @@ def possign(context, x, account):
return x if sign >= 0 else -x


# ``date`` type

class Date(types.Structure):
name = 'date'
columns = ColumnsRegistry()

@columns.register(int)
def year(x):
return x.year

@columns.register(int)
def month(x):
return x.month

@columns.register(int)
def day(x):
return x.day

types.ALIASES[datetime.date] = Date


@function([str], datetime.date)
@function([str, str], datetime.date)
def parse_date(string, frmt=None):
Expand Down

0 comments on commit 0aa0689

Please sign in to comment.