MaterialDatePicker todayInUtcMilliseconds method returning incorrect day

Viewed 268

When creating a MaterialDatePicker using the MaterialDatePicker.todayInUtcMilliseconds() method, our app is returning a timestamp that is a day out from the current date.

The simplified code we are using to display the MaterialDatePicker is as follows:

val picker: MaterialDatePicker<Long> = MaterialDatePicker.Builder.datePicker()
        .setInputMode(MaterialDatePicker.INPUT_MODE_CALENDAR)
        .setSelection(MaterialDatePicker.todayInUtcMilliseconds())
        .setTitleText("Custom title")
        .build()

        picker.run {
            addOnPositiveButtonClickListener(viewModel::updateContractDate)
            show(parentActivity.supportFragmentManager, picker.toString())
        }

Which, when displayed, is showing yesterdays date as selected (6 July) as seen below:

enter image description here

This is especially odd as the same sample code returns correctly on the same device when used in the Material Component library's sample 'catalog' app.

We are using the latest Material Library version 1.3.0-alpha01 and have observed this on Android 10 - API 29 and Android 8.1 - API 27. We are also utilizing Jake Wharton's ThreeTen Android Backport elsewhere in the app, but I am not sure if that is relevant.

Any help would be greatly appreciated!

2 Answers

This looks to be a bug as of the latest Material Component Library version 1.3.0-alpha01. It has been fixed but was not put into the build.

The suggested solution is to use a 'daily build' of the library by using the following in the top-level build.gradle file

    maven {
        name = "MaterialSnapshots"
        url = uri("https://maven.pkg.github.com/material-components/material-components-android")
        credentials {
            username = <github_username>
            password = <github_access_token>
        }
    }

and using the 1.3.0-dev-20200619 version as a dependency

It was a bug opened again with another bug.
Now it is fixed starting from the version 1.2.0-rc01 and 1.3.0-alpha02.

enter image description here

Related