Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify date/time operations with additional helper functions #46

Closed
nonprofittechy opened this issue Jan 26, 2018 · 2 comments
Closed

Comments

@nonprofittechy
Copy link
Contributor

nonprofittechy commented Jan 26, 2018

Date math with format_date is a little confusing with the requirement to convert the Docassemble built-in date type and the function name "format_date" doesn't make it clear you can use it for date math. EDIT: I see now that the format_date part is not needed.

  1. Get a date in the interview variable case.answer_date, and add 2 weeks to it:

format_date(as_datetime(case.answer_date) + date_interval(days=14))

With example 1, you need to change the format of the date in the interview into a datetime. Otherwise you get an error that is confusing for a novice like me:

Error
TypeError: coercing to Unicode: need string or buffer, relativedelta found

I tested it with format_date(today() + date_interval(days=14)) which worked, so today() appears to a return a datetime while Docassemble datatype: date does not.

I suggest adding wrapper functions for add_days, add_months, etc, or alternatively, add_dateinterval that accepts the same arguments as date interval. It should work without requiring the interview author to convert a Docassemble date to a datetime. I think for legal applications, add_days would be most common though? Perhaps also add_years?

E.g.: add_days(case.answer_date, 14) or add_dateinterval(case.answer_date, days=14). It should accept both the Docassemble date datatype and the datatype of the today() function.

@nonprofittechy
Copy link
Contributor Author

Alternatively--if it's not a breaking change, datatype: date could default to a datetime object instead of the current format, so it works with the existing examples?

@nonprofittechy
Copy link
Contributor Author

Resolved with commit 4b722c1

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

No branches or pull requests

1 participant