ankidroid/Anki-Android — pull request #158 by chajadan (2014-01-04 18:40:48+00:00)
Title: Do not start new day early

My new day was starting an hour earlier than it should. In the code, dates were being manipulated directly, by adding intervals of seconds to the date, but this was not functioning. For instance, when subtracting 285 days from a Calendar using the add() function, a different result was obtained than when attempting to ~directly~ subtract the same interval of seconds from the long variable obtain from the Calendar object. I hear this is common, and it has to do with many factors. I quote one netizen who says "As to the java.util.Calendar approach, you /basically/ need to use Calendar#add() in a counter loop to get the elapsed value for years, months and days. This takes leap years, daylight saving time and local-specific disturbances in time properly into account."

Note that I encountered a case where both times had the same DST_OFFSET and yet still these improper calculations were resulting, so this is not simply a daylights savings time issue. Also note, when manipulating values direction, we were exactly an hour off.

I encountered several posts that recommend using "Joda Time" ( http://joda-time.sf.net/ ) to manipulate dates. What I'm pushing here is fairly straightforward, but less than elegant than a direct implementation would be.