advancedFormat method
Formats the date with advanced format tokens.
Supports all standard tokens plus additional ones like Do, Qo, Mo,
DDDo, Wo, k, kk, X, x, GGGG, GG.
Implementation
String advancedFormat(String pattern) {
if (!isValid) {
return locale.invalidDate;
}
final buffer = StringBuffer();
var i = 0;
while (i < pattern.length) {
// Handle escaped text [...]
if (pattern[i] == '[') {
final closeIndex = pattern.indexOf(']', i);
if (closeIndex != -1) {
buffer.write(pattern.substring(i + 1, closeIndex));
i = closeIndex + 1;
continue;
}
}
// Try to match tokens (longest first)
final remaining = pattern.substring(i);
final token = _matchAdvancedToken(remaining);
if (token != null) {
buffer.write(_formatAdvancedToken(token));
i += token.length;
} else {
buffer.write(pattern[i]);
i++;
}
}
return buffer.toString();
}