|
| 1 | +# Table of Contents |
| 2 | + |
| 3 | +* [ALToolbox.ThreePartsDate](#ALToolbox.ThreePartsDate) |
| 4 | + * [check\_empty\_parts](#ALToolbox.ThreePartsDate.check_empty_parts) |
| 5 | + * [ThreePartsDate](#ALToolbox.ThreePartsDate.ThreePartsDate) |
| 6 | + * [validate](#ALToolbox.ThreePartsDate.ThreePartsDate.validate) |
| 7 | + * [transform](#ALToolbox.ThreePartsDate.ThreePartsDate.transform) |
| 8 | + * [default\_for](#ALToolbox.ThreePartsDate.ThreePartsDate.default_for) |
| 9 | + * [BirthDate](#ALToolbox.ThreePartsDate.BirthDate) |
| 10 | + * [validate](#ALToolbox.ThreePartsDate.BirthDate.validate) |
| 11 | + |
| 12 | +--- |
| 13 | +sidebar_label: ThreePartsDate |
| 14 | +title: ALToolbox.ThreePartsDate |
| 15 | +--- |
| 16 | + |
| 17 | +<a id="ALToolbox.ThreePartsDate.check_empty_parts"></a> |
| 18 | + |
| 19 | +#### check\_empty\_parts(item: str, default\_msg="{} is not a valid date") |
| 20 | + |
| 21 | +```python |
| 22 | +def check_empty_parts(item: str, |
| 23 | + default_msg="{} is not a valid date") -> Optional[str] |
| 24 | +``` |
| 25 | + |
| 26 | +Validate a date string in MM/DD/YYYY format and return specific error messages for missing parts. |
| 27 | + |
| 28 | +Analyzes a date string separated by forward slashes to determine which parts |
| 29 | +(month, day, year) are missing and returns a helpful error message indicating |
| 30 | +what needs to be entered. Currently only handles US date format. |
| 31 | + |
| 32 | +**Arguments**: |
| 33 | + |
| 34 | +- `item` _str_ - The date string to validate, expected in MM/DD/YYYY format. |
| 35 | +- `default_msg` _str, optional_ - Default error message template for invalid dates. |
| 36 | + Defaults to "\{\} is not a valid date". |
| 37 | + |
| 38 | + |
| 39 | +**Returns**: |
| 40 | + |
| 41 | + Error message if validation fails, None if date is valid. |
| 42 | + Returns None when the date is complete and valid, otherwise returns |
| 43 | + a localized error message indicating which parts need to be entered. |
| 44 | + |
| 45 | + |
| 46 | +**Example**: |
| 47 | + |
| 48 | + >>> check_empty_parts("12//2023") |
| 49 | + "Enter a day" |
| 50 | + >>> check_empty_parts("//") |
| 51 | + "Enter a month, a day, and a year" |
| 52 | + >>> check_empty_parts("12/25/2023") |
| 53 | + None |
| 54 | + |
| 55 | +<a id="ALToolbox.ThreePartsDate.ThreePartsDate"></a> |
| 56 | + |
| 57 | +## ThreePartsDate Objects |
| 58 | + |
| 59 | +```python |
| 60 | +class ThreePartsDate(CustomDataType) |
| 61 | +``` |
| 62 | + |
| 63 | +<a id="ALToolbox.ThreePartsDate.ThreePartsDate.validate"></a> |
| 64 | + |
| 65 | +#### validate(cls, item: str) |
| 66 | + |
| 67 | +```python |
| 68 | +@classmethod |
| 69 | +def validate(cls, item: str) -> bool |
| 70 | +``` |
| 71 | + |
| 72 | +Validate a date string in MM/DD/YYYY format. |
| 73 | + |
| 74 | +**Arguments**: |
| 75 | + |
| 76 | +- `item` _str_ - The date string to validate. |
| 77 | + |
| 78 | + |
| 79 | +**Returns**: |
| 80 | + |
| 81 | +- `bool` - True if valid or empty, raises DAValidationError if invalid. |
| 82 | + |
| 83 | + |
| 84 | +**Raises**: |
| 85 | + |
| 86 | +- `DAValidationError` - If the date string is invalid or cannot be parsed. |
| 87 | + |
| 88 | +<a id="ALToolbox.ThreePartsDate.ThreePartsDate.transform"></a> |
| 89 | + |
| 90 | +#### transform(cls, item) |
| 91 | + |
| 92 | +```python |
| 93 | +@classmethod |
| 94 | +def transform(cls, item) -> Optional[datetime] |
| 95 | +``` |
| 96 | + |
| 97 | +Transform a date string into a datetime object. |
| 98 | + |
| 99 | +**Arguments**: |
| 100 | + |
| 101 | +- `item` - The date string to transform. |
| 102 | + |
| 103 | + |
| 104 | +**Returns**: |
| 105 | + |
| 106 | + datetime or None: The parsed datetime object, or None if empty. |
| 107 | + |
| 108 | +<a id="ALToolbox.ThreePartsDate.ThreePartsDate.default_for"></a> |
| 109 | + |
| 110 | +#### default\_for(cls, item) |
| 111 | + |
| 112 | +```python |
| 113 | +@classmethod |
| 114 | +def default_for(cls, item) -> Optional[str] |
| 115 | +``` |
| 116 | + |
| 117 | +Convert a datetime object to MM/dd/yyyy format string. |
| 118 | + |
| 119 | +**Arguments**: |
| 120 | + |
| 121 | +- `item` - The datetime object to format. |
| 122 | + |
| 123 | + |
| 124 | +**Returns**: |
| 125 | + |
| 126 | + str or None: The formatted date string, or None if empty. |
| 127 | + |
| 128 | +<a id="ALToolbox.ThreePartsDate.BirthDate"></a> |
| 129 | + |
| 130 | +## BirthDate Objects |
| 131 | + |
| 132 | +```python |
| 133 | +class BirthDate(ThreePartsDate) |
| 134 | +``` |
| 135 | + |
| 136 | +<a id="ALToolbox.ThreePartsDate.BirthDate.validate"></a> |
| 137 | + |
| 138 | +#### validate(cls, item: str) |
| 139 | + |
| 140 | +```python |
| 141 | +@classmethod |
| 142 | +def validate(cls, item: str) -> bool |
| 143 | +``` |
| 144 | + |
| 145 | +Validate a birth date string ensuring it's a valid past date. |
| 146 | + |
| 147 | +Validates that the input is a properly formatted date string in MM/DD/YYYY |
| 148 | +format that represents a date on or before today and after the year 1000. |
| 149 | +Empty or None values are considered valid. |
| 150 | + |
| 151 | +**Arguments**: |
| 152 | + |
| 153 | +- `item` _str_ - The birth date string to validate in MM/DD/YYYY format. |
| 154 | + |
| 155 | + |
| 156 | +**Returns**: |
| 157 | + |
| 158 | + True if the date is valid, otherwise raises DAValidationError. |
| 159 | + |
| 160 | + |
| 161 | +**Raises**: |
| 162 | + |
| 163 | +- `DAValidationError` - If the date is invalid, improperly formatted, |
| 164 | + or in the future. |
| 165 | + |
0 commit comments