ordinal property

String get ordinal

Convert to ordinal string (1st, 2nd, 3rd, etc.)

Implementation

String get ordinal {
  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';
  }
}