Sunday, May 11, 2014

In Android May is month number four

So I published my Android app yesterday. But it didn't work as expected. Information was missing in the display. After debugging I found out that the missing information was not there in the parsed result either. Was there a bug in the XML parser? I debugged that too, but could not find anything that was wrong. Yet when I made the same search in the browser the information was there in the result.

And then I found it! It turned out that my app was searching not today's date, but a month ago. Most of the information was the same, but some was missing. The reason for this was that I pretty late in the project removed the ASAP I had used before and instead used a date field, automatically filled in with a date, that should have been today's, but was actually a month ago.

And the reason for this is how Android Calendar work:

  • calendar.get(Calendar.MONTH) will get you the month number where January is month zero
  • calendar.get(Calendar.DAY_OF_MONTH) will get you the day of the month, where the first day is one
Not very intuitive, even if I assume ther is some logic in it. Anyway, a quick bugfix and new upload to Google Play means that very few users, if any, have been affected.

No comments: