format method
String
format(
- dynamic year,
- dynamic month,
- dynamic day,
- dynamic format,
)
Implementation
String format(year, month, day, format) {
String newFormat = format;
String dayString;
String monthString;
String yearString;
if (language == 'ar') {
dayString = DigitsConverter.convertWesternNumberToEastern(day);
monthString = DigitsConverter.convertWesternNumberToEastern(month);
yearString = DigitsConverter.convertWesternNumberToEastern(year);
} else {
dayString = day.toString();
monthString = month.toString();
yearString = year.toString();
}
if (newFormat.contains("dd")) {
newFormat = newFormat.replaceFirst("dd", dayString);
} else {
if (newFormat.contains("d")) {
newFormat = newFormat.replaceFirst("d", day.toString());
}
}
//=========== Day Name =============//
// Friday
if (newFormat.contains("DDDD")) {
newFormat = newFormat.replaceFirst(
"DDDD", "${_local[language]!['days']![wkDay ?? weekDay()]}");
// Fri
} else if (newFormat.contains("DD")) {
newFormat = newFormat.replaceFirst(
"DD", "${_local[language]!['short_days']![wkDay ?? weekDay()]}");
}
//============== Month ========================//
// 1
if (newFormat.contains("mm")) {
newFormat = newFormat.replaceFirst("mm", monthString);
} else {
newFormat = newFormat.replaceFirst("m", monthString);
}
// Muharram
if (newFormat.contains("MMMM")) {
newFormat =
newFormat.replaceFirst("MMMM", _local[language]!['long']![month]!);
} else {
if (newFormat.contains("MM")) {
newFormat =
newFormat.replaceFirst("MM", _local[language]!['short']![month]!);
}
}
//================= Year ========================//
if (newFormat.contains("yyyy")) {
newFormat = newFormat.replaceFirst("yyyy", yearString);
} else {
newFormat = newFormat.replaceFirst("yy", yearString.substring(2, 4));
}
return newFormat;
}