Skip to content

Commit 14d80ba

Browse files
author
Amer C
authored
Localize date format
1 parent dc3f97d commit 14d80ba

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.text.TextPaint;
2222
import android.text.TextUtils;
2323
import android.text.format.DateFormat;
24+
import android.text.format.DateUtils;
2425
import android.text.style.StyleSpan;
2526
import android.util.AttributeSet;
2627
import android.util.TypedValue;
@@ -1302,8 +1303,10 @@ public DateTimeInterpreter getDateTimeInterpreter() {
13021303
@Override
13031304
public String interpretDate(Calendar date) {
13041305
try {
1305-
SimpleDateFormat sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE M/dd", Locale.getDefault()) : new SimpleDateFormat("EEE M/dd", Locale.getDefault());
1306-
return sdf.format(date.getTime()).toUpperCase();
1306+
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_NUMERIC_DATE;
1307+
String localizedDate = DateUtils.formatDateTime(getContext(), date.getTime(), flags);
1308+
SimpleDateFormat sdf = mDayNameLength == LENGTH_SHORT ? new SimpleDateFormat("EEEEE", Locale.getDefault()) : new SimpleDateFormat("EEE", Locale.getDefault());
1309+
return String.format("%s %s", sdf.format(date.getTime()).toUpperCase(), localizedDate);
13071310
} catch (Exception e) {
13081311
e.printStackTrace();
13091312
return "";

0 commit comments

Comments
 (0)