Skip to content

Rule to compare with months ago #53

Discussion options

You must be logged in to vote

You would use the TIMEDELTA data type that was added in v3.5. It doesn't support months exactly because months do not always have the same number of days. You can, however, check if the date is older than 90 days using ($today - t'P90D') > establishmentDate.

Example:

python -m rule_engine.debug_repl --edit-console
edit the 'context' and 'thing' objects as necessary
>>> import datetime
>>> thing = dict(name='Company Name', establishmentDate=datetime.date(2021, 4, 8))
>>> 
exiting the edit console...
rule > establishmentDate
result: 
datetime.datetime(2021, 4, 8, 0, 0, tzinfo=tzlocal())
rule > $today
result: 
datetime.datetime(2023, 2, 7, 0, 0, tzinfo=tzlocal())
rule > $today - t'P90D'
resu…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andre-picoli-ext-dock
Comment options

Answer selected by zeroSteiner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants