Think About Time

datetime.pngIrrespective of mobile platform, one thing that consistently causes unexpected problems on mobile projects is date/times. During project inception people often don’t think through all the complexities related to date/times and much further down the line early decisions or simplifications often come back to haunt projects. Here are some things to think about…
  • How will the whole system handle dates? Multiple platforms will want to store dates in different ways which is ok but how will these systems communicate dates? I have found that it’s best to agree this upfront to prevent unnecessary later re-work. Consider using Unix time or ISO8601.
  • Many mobile apps use SQLite to store data. Unfortunately, SQLite doesn’t have a date type. It’s simplest to use integers to store Unix time. Avoid storing them as arbitrary strings as they then can’t be compared/sorted via SQL unless stored as ISO8601. Also, storing as strings usually implies storing defined by some sort of locale (location specific formatting) that you should avoid.
  • Think about how dates will be displayed. They should change with the locale (location specific formatting) set for the mobile device. Use the locale when programming times and don’t hardcode display formats.
  • Think about how you will handle and display different time zones. This can be especially problematic where mobile devices are sending timestamped data from multiple timezones. Also think about how you will handle the case where timezones themselves change i.e. some country decides to change their zone. See below for some tips.
  • Programming date/times can be tricky. Use libraries rather than rolling your own to avoid stupid errors. On Android and other Java platforms many of the earlier written Java time APIs are deprecated because it became apparent that they weren’t as fit for use as people first thought. If you program Android, joda-time-android has recently become available. Using Joda allows you to ship new timezone data with updated apps rather than relying on timezone updates in OS updates – that obviously happen not so often or not at all on many Android devices.