core.convert¶
Functions¶
convert_str_month_to_number_month ¶
Convert month string to standardized month name.
Takes a month string in various formats and converts it to a standardized title-case month name. Handles abbreviations, full names, and combinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
month | str | Month string to convert. Can be in various formats like "jan", "January", "01", "jan-feb", etc. | required |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | Standardized month name in title case, or original string if conversion fails. |
Examples:
>>> convert_str_month_to_number_month("jan")
'January'
>>> convert_str_month_to_number_month("01")
'January'
>>> convert_str_month_to_number_month("jan-feb")
'January-February'
>>> convert_str_month_to_number_month("invalid")
'invalid'
Source code in pyadvtools/core/convert.py
convert_to_ordered_number ¶
Convert an integer to its ordinal form (1st, 2nd, 3rd, etc.).
Converts a non-negative integer to its ordinal representation by adding the appropriate suffix (st, nd, rd, th) based on the number's ending.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number | int | The integer to convert to ordinal form. Negative numbers are returned unchanged. | required |
Returns:
| Type | Description |
|---|---|
str | int | Union[str, int]: Ordinal string for non-negative numbers, original integer for negative numbers. |
Examples:
>>> convert_to_ordered_number(1)
'1st'
>>> convert_to_ordered_number(2)
'2nd'
>>> convert_to_ordered_number(3)
'3rd'
>>> convert_to_ordered_number(4)
'4th'
>>> convert_to_ordered_number(21)
'21st'
>>> convert_to_ordered_number(-5)
-5
Source code in pyadvtools/core/convert.py
months_dict ¶
Create a dictionary mapping month names to their numeric representations.
Generates a comprehensive dictionary that maps various month name formats to their corresponding string or integer representations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
str_int | str | Format for the output values. "str" returns string numbers, "int" returns integer numbers, anything else returns empty dict. | 'str' |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | Dictionary mapping month names (lowercase) to their numeric representations. Keys include full names, abbreviations, and numeric strings. |
Examples:
>>> months = months_dict("str")
>>> months["january"]
'1'
>>> months["jan"]
'1'
>>> months["01"]
'1'
Source code in pyadvtools/core/convert.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
months_list ¶
Generate a comprehensive list of month representations.
Creates a list containing various formats of month names and numbers, including individual months, combinations, and seasonal terms.
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: List of month representations including: - Single digit months (1-12) - Zero-padded months (01-12) - Full month names (January-December) - Abbreviated month names (Jan-Dec) - Alternative abbreviations (Sept) - Seasonal terms (spring, summer, fall, winter, quarter) - Combinations with hyphens and slashes |
Examples:
>>> months = months_list()
>>> "January" in months
True
>>> "01" in months
True
>>> "spring" in months
True
>>> "jan-feb" in months
True