I’m having fun with dates in flex, and had a strange bug showing up. It turned out to be not-really-a-bug, but a somewhat strange way of the way Flex works with dates. Namely,
dateSelected.selectedDate.fullYearUTC returns 4 digit year number,
dateSelected.selectedDate.dateUTC returns day number, from 1 to 31, while
dateSelected.selectedDate.monthUTC returns month number from 0 to 11 (!!!).
What’s up with that? Is there some good reason not all fields are treated the same way? I kinda guess there is, but was unable to find the ‘why’ part.
Cheers
While the handling of dates in ActionScript (and many other languages) certainly is not ideal, there actually is a somewhat understandable logic to this:
You have to picture the inner workings of the Date class as arrays. While the year and date numbers are assigned to a period of time (think of it as the array’s value at a specified index ) – the day of the week, month, etc., represent the index number (think of it as the array’s key).
In flex, index numbers start at 0, so try to picture these arrays in code:
and these are most interesting: