getMonthName method
Returns the name of a month corresponding to the integer value.
This method assumes that the integer represents a month number (1-12). If the integer is outside this range, it returns 'Invalid number of month'.
Parameters:
isShort
: If true, returns the abbreviated month name. Defaults to false.
Returns: A String representing the month name.
Example:
print(1.getMonthName()); // Output: January
print(3.getMonthName(isShort: true)); // Output: Mar
print(13.getMonthName()); // Output: Invalid number of month
Implementation
String getMonthName({bool isShort = false}) {
final Map<int, String> monthNames = <int, String>{
1: isShort ? 'Jan' : 'January',
2: isShort ? 'Feb' : 'February',
3: isShort ? 'Mar' : 'March',
4: isShort ? 'Apr' : 'April',
5: 'May',
6: isShort ? 'Jun' : 'June',
7: isShort ? 'Jul' : 'July',
8: isShort ? 'Aug' : 'August',
9: isShort ? 'Sep' : 'September',
10: isShort ? 'Oct' : 'October',
11: isShort ? 'Nov' : 'November',
12: isShort ? 'Dec' : 'December',
};
return monthNames[this] ?? 'Invalid number of month';
}