Skip to main content

ALToolbox.ThreePartsDate

CustomDataType​

DAValidationError​

DADateTime​

word​

as_datetime​

today​

date_difference​

log​

Optional​

datetime​

re​

__all__​

js_text​

check_empty_parts​

def check_empty_parts(item: str,
default_msg="{} is not a valid date") -> Optional[str]

Validate a date string in MM/DD/YYYY format and return specific error messages for missing parts.

Analyzes a date string separated by forward slashes to determine which parts (month, day, year) are missing and returns a helpful error message indicating what needs to be entered. Currently only handles US date format.

Arguments​

  • item str - The date string to validate, expected in MM/DD/YYYY format.
  • default_msg str, optional - Default error message template for invalid dates. Defaults to "{} is not a valid date".

Returns​

Error message if validation fails, None if date is valid. Returns None when the date is complete and valid, otherwise returns a localized error message indicating which parts need to be entered.

Example​

In an English interview, the value of missing_part_message is:

Input (interview YAML)

code: |
from docassemble.ALToolbox.ThreePartsDate import check_empty_parts
missing_part_message = check_empty_parts("12//2023")

Output

Enter a day

ThreePartsDate Objects​

class ThreePartsDate(CustomDataType)

A custom date input with separate month, day, and year controls.

In an interview:

Input (interview YAML)

modules:
- docassemble.ALToolbox.ThreePartsDate
question: |
Appointment date
fields:
- Appointment date: appointment_date
datatype: ThreePartsDate

name​

input_type​

javascript​

jq_message​

is_object​

mako_parameters​

validate​

@classmethod
def validate(cls, item: str) -> bool

Validate a date string in MM/DD/YYYY format.

Arguments​

  • item str - The date string to validate.

Returns​

  • bool - True if valid or empty, raises DAValidationError if invalid.

Raises​

  • DAValidationError - If the date string is invalid or cannot be parsed.

Example​

Docassemble normally calls this automatically for the datatype. For a direct validation check, the value of valid_date is:

Input (interview YAML)

code: |
valid_date = ThreePartsDate.validate("01/02/1990")

Output

True

transform​

@classmethod
def transform(cls, item) -> Optional[DADateTime]

Transform a date string into a datetime object.

Arguments​

  • item - The date string to transform.

Returns​

datetime or None: The parsed datetime object, or None if empty.

Example​

Docassemble normally transforms the submitted field automatically. For a direct conversion, the value of date_label is:

Input (interview YAML)

code: |
parsed_date = ThreePartsDate.transform("01/02/1990")
date_label = parsed_date.format("yyyy-MM-dd")

Output

1990-01-02

default_for​

@classmethod
def default_for(cls, item) -> Optional[str]

Convert a datetime object to MM/dd/yyyy format string.

Arguments​

  • item - The datetime object to format.

Returns​

str or None: The formatted date string, or None if empty.

Example​

With users[0].birthdate set to January 2, 1990, the value of date_input is the string used to repopulate the widget:

Input (interview YAML)

code: |
date_input = ThreePartsDate.default_for(users[0].birthdate)

Output

01/02/1990

BirthDate Objects​

class BirthDate(ThreePartsDate)

A three-part date input that rejects future dates of birth.

In an interview:

Input (interview YAML)

modules:
- docassemble.ALToolbox.ThreePartsDate
question: |
Date of birth
fields:
- Date of birth: users[0].birthdate
datatype: BirthDate

name​

input_type​

javascript​

jq_message​

is_object​

mako_parameters​

validate​

@classmethod
def validate(cls, item: str) -> bool

Validate a birth date string ensuring it's a valid past date.

Validates that the input is a properly formatted date string in MM/DD/YYYY format that represents a date on or before today and after the year 1000. Empty or None values are considered valid.

Arguments​

  • item str - The birth date string to validate in MM/DD/YYYY format.

Returns​

True if the date is valid, otherwise raises DAValidationError.

Raises​

  • DAValidationError - If the date is invalid, improperly formatted, or in the future.

Example​

Docassemble normally calls this automatically for the datatype. For a direct validation check, the value of valid_date is:

Input (interview YAML)

code: |
valid_date = BirthDate.validate("01/02/1990")

Output

True