toMonthDaySuffix method

String toMonthDaySuffix()

Implementation

String toMonthDaySuffix() {
  if (!(this! >= 1 && this! <= 31)) {
    throw Exception('Invalid day of month');
  }

  if (this! >= 11 && this! <= 13) {
    return '$this th';
  }

  switch (this! % 10) {
    case 1:
      return '$this st';
    case 2:
      return '$this nd';
    case 3:
      return '$this rd';
    default:
      return '$this th';
  }
}