diff --git a/lib/java/com/google/android/material/datepicker/DateStrings.java b/lib/java/com/google/android/material/datepicker/DateStrings.java index 9c5a82c10b8..ef29c6a6a3d 100644 --- a/lib/java/com/google/android/material/datepicker/DateStrings.java +++ b/lib/java/com/google/android/material/datepicker/DateStrings.java @@ -35,6 +35,9 @@ class DateStrings { private DateStrings() {} static String getYearMonth(long timeInMillis) { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + return UtcDates.getYearMonthFormat(Locale.getDefault()).format(new Date(timeInMillis)); + } int flags = DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_UTC; return DateUtils.formatDateTime(null, timeInMillis, flags); } diff --git a/lib/java/com/google/android/material/datepicker/UtcDates.java b/lib/java/com/google/android/material/datepicker/UtcDates.java index 27a70c07dbf..69ad28c1f9a 100644 --- a/lib/java/com/google/android/material/datepicker/UtcDates.java +++ b/lib/java/com/google/android/material/datepicker/UtcDates.java @@ -19,6 +19,7 @@ import android.annotation.TargetApi; import android.content.res.Resources; +import android.icu.text.DisplayContext; import android.os.Build.VERSION_CODES; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -138,6 +139,7 @@ private static android.icu.text.DateFormat getAndroidFormat(String pattern, Loca android.icu.text.DateFormat format = android.icu.text.DateFormat.getInstanceForSkeleton(pattern, locale); format.setTimeZone(getUtcAndroidTimeZone()); + format.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE); return format; } @@ -183,6 +185,11 @@ private static SimpleDateFormat getSimpleFormat(String pattern, Locale locale) { return format; } + @TargetApi(VERSION_CODES.N) + static android.icu.text.DateFormat getYearMonthFormat(Locale locale) { + return getAndroidFormat(android.icu.text.DateFormat.YEAR_MONTH, locale); + } + @TargetApi(VERSION_CODES.N) static android.icu.text.DateFormat getYearAbbrMonthDayFormat(Locale locale) { return getAndroidFormat(android.icu.text.DateFormat.YEAR_ABBR_MONTH_DAY, locale); diff --git a/lib/java/com/google/android/material/datepicker/res/layout/mtrl_picker_header_dialog.xml b/lib/java/com/google/android/material/datepicker/res/layout/mtrl_picker_header_dialog.xml index ab8865599ea..f214ef45d67 100644 --- a/lib/java/com/google/android/material/datepicker/res/layout/mtrl_picker_header_dialog.xml +++ b/lib/java/com/google/android/material/datepicker/res/layout/mtrl_picker_header_dialog.xml @@ -22,6 +22,8 @@