getWeekName method
Returns the name of a week day corresponding to the integer value.
This method assumes that the integer represents a day of the week (1-7), where 1 is Monday and 7 is Sunday. If the integer is outside this range, it returns 'Invalid number of week'.
Parameters:
isShort
: If true, returns the abbreviated day name. Defaults to false.
Returns: A String representing the day name.
Example:
print(1.getWeekName()); // Output: Monday
print(5.getWeekName(isShort: true)); // Output: Fri
print(8.getWeekName()); // Output: Invalid number of week
Implementation
String getWeekName({bool isShort = false}) {
final Map<int, String> weekNames = <int, String>{
1: isShort ? 'Mon' : 'Monday',
2: isShort ? 'Tue' : 'Tuesday',
3: isShort ? 'Wed' : 'Wednesday',
4: isShort ? 'Thu' : 'Thursday',
5: isShort ? 'Fri' : 'Friday',
6: isShort ? 'Sat' : 'Saturday',
7: isShort ? 'Sun' : 'Sunday',
};
return weekNames[this] ?? 'Invalid number of week';
}