intDayToStringDay static method
Converts a DateTime weekday integer to its corresponding day name string.
Maps DateTime weekday constants (1-7) to their full English day names. Uses modulo arithmetic to handle both DateTime constants and custom day values.
Parameters:
day: Integer representing the day of week (1=Monday through 7=Sunday in DateTime)
Returns the full English name of the day (e.g., "Monday", "Tuesday")
Throws an exception if the day value doesn't map to a valid weekday.
Example:
final dayName = RtCommonFunction.intDayToStringDay(DateTime.monday); // "Monday"
final dayName2 = RtCommonFunction.intDayToStringDay(1); // "Monday"
final dayName3 = RtCommonFunction.intDayToStringDay(7); // "Sunday"
Note: DateTime.monday = 1, DateTime.tuesday = 2, ..., DateTime.sunday = 7
Implementation
static String intDayToStringDay(int day) {
if (day % 7 == DateTime.monday % 7) return 'Monday';
if (day % 7 == DateTime.tuesday % 7) return 'Tuesday';
if (day % 7 == DateTime.wednesday % 7) return 'Wednesday';
if (day % 7 == DateTime.thursday % 7) return 'Thursday';
if (day % 7 == DateTime.friday % 7) return 'Friday';
if (day % 7 == DateTime.saturday % 7) return 'Saturday';
if (day % 7 == DateTime.sunday % 7) return 'Sunday';
throw '🐞 This should never have happened: $day';
}