Reference¶
dsg_lib.common_functions.calendar_functions
¶
This module provides two main functions to convert between month numbers and their corresponding names.
Functions:
Name | Description |
---|---|
get_month |
int) -> str: Converts an integer month number to its corresponding month name. Args: month (int): An integer between 1 and 12 representing the month number. Returns: str: The full name of the month corresponding to the input month number. If the input is not within the range of 1-12, returns "Invalid month number". If the input is not an integer, returns "Invalid input, integer is required". |
get_month_number |
str) -> int: Converts a month name to its corresponding month number. Args: month_name (str): A string containing the full name of a month. Returns: int: The month number corresponding to the input month name. If the input is not a valid month name, returns -1. If the input is not a string, returns "Invalid input, string is required". |
Example:
from dsg_lib.common_functions.calendar_functions import get_month,
get_month_number print(get_month(1))
# Outputs: 'January'
print(get_month_number('January'))
# Outputs: 1
This module is part of the dsg_lib package and is used for handling and converting between month numbers and names.
Author: Mike Ryan Date: 2024/05/16 License: MIT
get_month(month)
¶
Converts an integer month number to its corresponding month name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
month
|
int
|
An integer or integer-like float between 1 and 12 |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The full name of the month corresponding to the input month number. If the input is not within the range of 1-12, returns "Invalid month number". If the input is not an integer or integer-like float, returns "Invalid input, integer is required". |
Source code in dsg_lib/common_functions/calendar_functions.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
get_month_number(month_name)
¶
Converts a month name to its corresponding month number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
month_name
|
str
|
A string containing the full name of a month. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The month number corresponding to the input month name. If the input is not a valid month name or not a string, returns -1. |
Source code in dsg_lib/common_functions/calendar_functions.py
109 110 111 112 113 114 115 116 117 118 119 120 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 |
|