Skip to content

Commit

Permalink
CHANGELOG: Added Islamic Calendar custom format
Browse files Browse the repository at this point in the history
Signed-off-by: DHD2280 <[email protected]>
  • Loading branch information
DHD2280 committed Jan 23, 2025
1 parent ba3477d commit dc964b7
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.icu.text.DateFormat;
import android.icu.util.IslamicCalendar;
import android.icu.util.ULocale;
import android.text.SpannableStringBuilder;
import android.util.Log;

Expand Down Expand Up @@ -148,6 +151,33 @@ private CharSequence georgianDateOf(String format) {
}
}

private CharSequence islamDateOf(String format) {
try {
String calendarTag;
char type = !format.isEmpty() ? format.charAt(0) : '\0';
if (type == 'C') {
calendarTag = "islamic-civil";
format = format.substring(1);
} else if (type == 'U') {
calendarTag = "islamic-umalqura";
format = format.substring(1);
} else {
calendarTag = "islamic"; // Default Islamic
}
IslamicCalendar islamicCalendar = new IslamicCalendar(
new ULocale("@calendar=" + calendarTag).toLocale()
);
@SuppressLint("SimpleDateFormat")
DateFormat dateFormat = new android.icu.text.SimpleDateFormat(format, ULocale.ENGLISH);
dateFormat.setCalendar(islamicCalendar);
String result = dateFormat.format(islamicCalendar.getTime());
hasDate = true;
return result;
} catch (Exception ignored) {
return "$I" + format;
}
}

private CharSequence lunarDate() {
try {
return getLunarDate();
Expand Down Expand Up @@ -197,6 +227,7 @@ public CharSequence formatString(String input) {
private CharSequence valueOf(String match) {
return switch (match.substring(0, 1)) {
case "G" -> georgianDateOf(match.substring(1));
case "I" -> islamDateOf(match.substring(1));
case "P" -> persianDateOf(match.substring(1));
case "T" -> temperatureOf(match.substring(1));
case "L" -> lunarDate();
Expand Down

0 comments on commit dc964b7

Please sign in to comment.