Sunday, 12 July 2009

Testing on the Bog - Testing Dates and Times

PDF version for placing in your office.

What is Testing on the Bog?

The handling of dates and times is one area that commonly has issues when to comes to testing. This Testing on the Bog will give you some ideas when it comes to testing dates and times in your application, this doesn't tell you how to do it, as you need to know what your application should be doing in these situations.

Date Formats - Most of the world uses Day then Month while the US for example uses Month then Day. Then there is also the ISO8601 format for dates. Does the application format correct, accept input correctly, store and convert correctly? Does it reject input when expected?

Two Digit Years - This was the whole issue around Y2k problem. When the application is faced with a two digit does it do something sensible with it? Does it store correct by adding 19 or 20 to the front or does it add 00? If you roll your clock forwards is it still adding the century correctly?

Daylight Saving - Does the application handle the short day and the long day correctly? In the long day can you tell the difference between the first hour and the second hour that is doubled up? For example ':' maybe used for the first hour and ';' is used for the second hour e.g. 02:59 is followed by 02;00.

Daylight Saving Dates - Does your application use the correct library for figuring out the start and end dates? This is particularly important if the local rules have been recently changed.

Time Zones - Are Time Zones stored? Does convert correctly? When no Time Zone is given does it correctly figure out what time zone it should be? Transitions in and out of Day Light Savings Time Zones. If you manually ask the system (e.g. via SQL) to convert the time zone will it? If you manually force a date to be inserted with a Time Zone which is different the the default does the application do the correct thing with it?

Leap Years - Firstly remember the rule is "Every year divisible by 4 expect those divisible by 100 unless it is also divisible by 400" 1900 was not a leap year yet 2000 was. Do things work as expected in this day? Date range calculations? Is 365 hard coded anywhere for calculations?

Leap Seconds - Leap seconds happen every so often and result in an extra second being added to the day (and in theory a second may also be removed). So the valid range of seconds in a minute is 59 - 61. A leap second minute goes x:59. x:60, y:00. Can the application display a minute with 61 seconds? What happens if you insert a time with 60 as the value of seconds? What happens with a transaction submitted at 61? Does the application assume there are always 86400 seconds in a day?

Intervals - With Leap Years, Leap Seconds and Daylight Savings do intervals take these into account correctly?

Year 2038 Problem - At 2038-01-19T03:14:07Z the 32bit counter which has been counting the number of seconds since 1970-01-01T00:00:00Z will roll over to a negative integer which may produce date/times in the past.


Steve Allen said...

If the interval calculation requires being legally precise then there is a lot of code and configuration to be considered.

The inability of national governments to harmonize on this underlies the leap second issues.