material-components / material-components/material-components-android
[MaterialDatePicker] Choose different Calendar API and define custom DateTime Format
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
The current issue is that `MaterialDatePicker` is using `java.util.Calendar` (Java 7) as an underlying API to get UTC epoch millisecond and datetime format, and convert it to [`Month`](https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/datepicker/Month.java) object where `year` property is retrieved from `Calendar.get(Calendar.YEAR)`. This causes date string to always show year in Christian Era and/or B.C.E. As a Thai user, most of Thai are familiar with Buddhist Calendar (Buddhist year = Christian year + 543 e.g. 2021 = 2564), so elder users tend to not know which Christian year of their birthdate.
**Describe the solution you'd like**
- It would be great if we can customize or delegate how `Month` object is created, so it does not limit to only `java.util.Calendar` API, but open to `java.time.chrono.ThaiBuddhistDate` or `org.threeten.bp.chrono.ThaiBuddhistDate` (Threeten ABP).
```Kotlin
MaterialDatePicker.Builder
.datePicker()
.setCustomMonth(CustomMonth())
```
```Kotlin
open class CustomMonth(private val thaiBuddhistDate: ThaiBuddhistDate) : Month() {
override fun getYear(): Int {
return thaiBuddhistDate.getLong(ChronoField.YEAR).toInt()
}
}
```
- Moreover, a custom date format should be a feature of `MaterialDatePicker` as well.
**Additional context**
Example screenshots from another library ([ThaiDateTimePicker](https://github.com/layerlre/ThaiDateTimePicker) - **very old library**)

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/java/com/google/android/material/datepicker/Month.java and the MaterialDatePicker entry point to understand how Calendar supplies the year and formatting data. Compare the requested custom chronology and date-format support with the existing API boundaries. Done would require an agreed design and corresponding support for non-Gregorian years and custom formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100