Office Hours — Today, May 30

Tuesday, May 28

May 30
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:35 PM
Mark
has entered the room
Mark
hey mark
Mark M.
hello, Mark!
how can I help you today?
(besides complimenting you on your awesome first name)
Mark
haha
7:40 PM
Mark
I'm having some trouble setting the minDate on a DatePicker. I have 2 DatePicker widgets. If I select a date from the first one, I want to make that the minDate int the second one
I set the listener and it gets hit and calls this method
View paste
fun setSecondCalendar(firstDate: LocalDate) {
  secondPickerDialog.datePicker.updateDate(firstDate.year, firstDate.month.value-1, firstDate.dayOfMonth)
  val startOfTheDay = firstDate.atStartOfDay(ZoneId.of("Z”))
  val secondsSince1970 = startOfTheDay.toEpochSecond()
  SecondPickerDialog.datePicker.minDate = secondsSince1970
}
unfortunately a min date is not set
Mark M.
what are you using for LocalDate? the one from the Android SDK? Joda Time? ThreeTenABP?
Mark
threeten
7:45 PM
Mark M.
hmmm... Jake's repo isn't behaving for me, and I'm not seeing toEpochSecond() on LocalDateTime...
anyway, you're sure your code is getting called? and does startOfTheDay look OK?
Mark
View paste
It is getting called and startOfTheDay returns a ZoneDateTime.  https://www.threeten.org/threetenbp/apidocs/org/threeten/bp/ZonedDateTime.html
I initalized the calendar with minDate fine.  After this callback is invoked all the dates are selectable again
7:50 PM
Mark M.
I don't see toEpochSecond() there either -- perhaps it's a Kotlin extension function
anyway, either secondsSince1970 is coming out wrong, or DatePicker is not liking the changed minDate for some other reason
Mark
it is inherited through ChronoZonedDateTime
Mark M.
ah, OK, I see it now
I'd try changing SecondPickerDialog.datePicker.minDate = secondsSince1970 to use a known good value -- use https://www.epochconverter.com/ or something to get that value
if that works, then your problem is in your conversion code
if that fails, then your problem is in DatePicker
there are a variety of calendar widgets available in the Android Arsenal if DatePicker turns into a problem
Mark
the debugger displays 2019-06-20T00:00 for june 20
7:55 PM
Mark
ok
Mark M.
check the secondsSince1970 value on https://www.epochconverter.com/, since it can convert both ways
Mark
thank you
i will
before i go, I changed to different values in updateDate and noticed the calendar and the bar above can show different dates
Mark M.
what device are you testing on? is this consistent across multiple devices?
Mark
an emulated pixel
Mark M.
OK, that's really strange, as that should be a clean implementation
there is always the risk of a device manufacturer tinkering with these things and screwing something up, which is why I asked
I haven't used DatePicker in quite some time, and if I needed a date picker, I'd be using one of the library implementations, most likely
Mark
i have not tested across different devices. So regardless of the values passed to updateDate the calendar widget and the bar above it showing the date should always be in sync? I was afraid that maybe updateDate only affecte the bar above since that is always updating. Sometimes the calendar itself doesnt
8:00 PM
Mark
ok
Mark M.
I haven't even *looked* at a DatePicker in probably 2 years, so I'm not 100% certain what the behavior is supposed to be, but off the cuff, what you describe sounds strange
Mark
I will test with some other emualted devices
Mark M.
focus on different OS versions
Mark
OK
Mark M.
the emulator "device" is just for things like screen resolution
Mark
thank you and goodnight
Mark M.
you're welcome!
Mark
has left the room
8:25 PM
Mark M.
turned off guest access

Tuesday, May 28

 

Office Hours

People in this transcript

  • Mark
  • Mark Murphy