News for hackers. Stuff that matters.
Re:Android 4.2: December month missing in calendar by erydo on Saturday November 17, 2012 @07:29PM (#4799437)
According to this comment: https://code.google.com/p/android/issues/detail?id=39692#c17

It's caused by the convention of the Android datepicker to store month values as 0-11 instead of 1-12.

Dates are given in 1-31 as expected; and years are given in e.g. 2012 as expected; but months are given in 0-11 which is totally inconsistent with how people normally number months and how the rest of the API works.

So for January 1st, 2012, printing 'getDate()', 'getMonth()', and 'getYear()' would yield '1-0-2012'. It's a badly designed API and I'm surprised there aren't more instances of this breaking.

(I ran into this once in our codebase, but we managed to fix it pretty quickly).

Re:Android 4.2: December month missing in calendar by trimbo on Saturday November 17, 2012 @07:37PM (#4799447)
> months are given in 0-11 which is totally inconsistent with how people normally number months and how the rest of the API works

That numbering is consistent with Java and the constants in the Android API.

http://docs.oracle.com/javase/1.4.2/docs/api/constant-values...

http://developer.android.com/reference/java/util/Calendar.ht...

Re:Android 4.2: December month missing in calendar by erydo on Saturday November 17, 2012 @07:43PM (#4799457)
You're right, and I didn't doubt that. I meant it's self-inconsistent with how days and years are handled, not necessarily inconsistent with other calendar APIs within Java and Android. Sorry I wasn't clear.
Re:Android 4.2: December month missing in calendar by solarexplorer on Saturday November 17, 2012 @10:11PM (#4799700)
I guess the idea is to use the month as an array index to convert it into a string. You don't usually convert the day of month or the year into a string.

Nontheless I agree that it's bad API design.

Re:Android 4.2: December month missing in calendar by pwg on Sunday November 18, 2012 @10:15AM (#4800686)
Then declare the array with 13 slots, fill slots 1-12 with the appropriate strings, and don't use slot 0. Or better, put in an error check for being passed a zero.

Suddenly, a 1-12 value for "month" is directly an index into an array to convert the number into a string...

Re:Android 4.2: December month missing in calendar by mappu on Saturday November 17, 2012 @08:01PM (#4799502)
Javascript is the same. On 2012-11-18;

    >> (new Date()).getMonth();
    10
but getFullYear() and getDate() give 2012 and 18 as expected.
Re:Android 4.2: December month missing in calendar by king_jester on Saturday November 17, 2012 @09:44PM (#4799662)
The Java calendar and date APIs are the worst for this and several other design flaws that come back to bite you. There's a reason why JodaTime (http://joda-time.sourceforge.net/) is so popular.
Re:Android 4.2: December month missing in calendar by ajross on Saturday November 17, 2012 @10:28PM (#4799732)
All calendrics APIs will bite you. It's not a property of the API (though I agree Java's is bad) but of the problem domain. The gregorian calendar is simply a mess, and any API on that is just a facade on the mess. Never trust your calendar API. Never fool yourself into thinking you've found the right one. Always be very, very afraid when you find yourself doing arithmetic on a "date".
Re:Android 4.2: December month missing in calendar by sk5t on Sunday November 18, 2012 @12:59AM (#4799996)
Right on... Jon Skeet offers a very fine article on the slipperyness of date-time arithmetic here (it's about .NET and Noda Time, but the same issues apply): http://noda-time.blogspot.com/2011/08/what-wrong-with-dateti...