formatBuddhistEra method

String formatBuddhistEra(
  1. String pattern
)

Formats the date using Buddhist Era year tokens.

Supports BBBB for 4-digit BE year and BB for 2-digit BE year. All other tokens work the same as standard format().

Implementation

String formatBuddhistEra(String pattern) {
  if (!isValid) {
    return locale.invalidDate;
  }

  // Replace Buddhist Era tokens before standard formatting
  var result = pattern;
  result = result.replaceAll('BBBB', buddhistYear.toString().padLeft(4, '0'));
  result = result.replaceAll(
    'BB',
    buddhistYearShort.toString().padLeft(2, '0'),
  );

  return format(result);
}