getOrdinal method

String getOrdinal()

Returns the ordinal day number. Ex. 11th, 1st, 2nd, etc.

Implementation

String getOrdinal() {
  if (day >= 11 && day <= 13) {
    return "${day}th";
  }

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