Theory 
NSW Schools
Maths
Science
Documentation
Efficiency
Media
Databases
E-commerce
Reporting
Reviews
Data
Simulation
Maths
Computing
Encoding
 

Theory

Dates, Time & Computing

Preliminary Reading

Defining a year or even a day is not something that can be done easily. It was not until 1 October 1949, when Mao Zedong declared that China would follow the Gregorian calendar, that the entire world agreed what the date was for the very first time.

We work with dates everyday without giving it a second moments consideration but dates have always presented challenges for computing. Powerful tools are required in order to manipulate dates, for example:

Day Time

The practical measurement of time formerly depended on determining the period of rotation of the earth relative to the astronomical objects (most notably our sun). Today, atomic clocks provide a uniform time-scale which can be used as the basis for coordinated universal time (UTC).

The mean solar day, or average period of time taken by the earth to make one complete spin on its axis, has been determined as 24 hours 3 minutes and 56.5 seconds. The mean solar day is used to define solar time.

The day according to civil time begins at midnight. Periodically civil time needs to be adjusted by one-second increments to ensure consistency with the earth’s rotational time scale remains within 0.9 seconds. However, civil time is usually not used, since it depends on the observer’s longitude.

Standard time, which is the same throughout a given time zone, is generally adopted. Under this scheme the earth is divided into 24 time zones, each of which is about 15° of longitude wide and corresponds to one hour of time. Within a zone all civil clocks are set to the same local solar time.

The Year

The solar or tropical year is the time between successive points in time at which the sun appears to cross the equator from south to north pole. It has been determined as 365 days, 5 hr, 48 min, 46 sec of mean solar time.

The sidereal year, is the time required for the earth to complete one revolution of the sun as measured relative to the stars. The sidereal year is approximately 365 days, 6 hr, 8 min, of mean solar time and is therefore longer than the tropical year by about 20 minutes.

The calendar year now always contains a whole number of days, the ordinary year being 365 days and the leap year 366 days.

What was the y2k problem

Back in the 1970s and 1980s computers had far less power than they do today and programs were written to use as little memory as possible. Consequently many programs that stored dates just stored years using two digits. 1985 would have been stored as 85 and 1996 would have been stored as simply 96. At the turn of the century it was anticipated that this could cause many problems since the programs would literally run out of dates and they would either crash or simply reset themselves at year 00. As a direct consequence of this fact many millions of programs and microchips had to be checked to see how they would cope with a change of century. This was a very expensive and time consuming exercise.

"For example, to calculate how old you are a program will take today's date and subtract your birthdate from it. That subtraction works fine on two-digit year dates until today's date and your birthdate are in different centuries. Then the calculation no longer works. For example, if the program thinks that today's date is 1/1/00 and your birthday is 1/1/65, then it may calculate that you are -65 years old rather than 35 years old. As a result, date calculations give erroneous output and software crashes or produces the wrong results." (http://computer.howstuffworks.com)

Preliminary Exercise: Calculating Days of the Week

 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Day #1234567
Day # mod 70.140.290.430.570.710.860
Day #891011121314
Day # mod 7       
Day #15161718192021
Day # mod 7       

If the first day of the year is Sunday what day of the week will the following days be

If today is Friday (day 1) what day of the week it will be in

Birthdays and leap years


Exercises / Calculations

timeanddate.com

Exercise 1

Visit timeanddate.com and

Excel Dates

Day Numbers

Exercise 2

January 0 1900 and Date Overflows

Exercise 3

Graphic showing day numbers and dates in Microsoft Excel

WWII Date Count

Exercise 4

According to the BBC internet site World War Two in Europe began on 3 September 1939 when Britain and France declared war on Germany. World War Two can be deemed to have ended when Emperor Hirohito made his first ever broadcast to the Japanese people on 15 August 1945. Hirohito remarked that the war did not turn in Japan's favour.

Unix Dates

Unix figures out all its dates by counting the number of seconds since midnight 1 January 1970. The Unix time stamp will report the number of seconds since this time, which is when time began for Unix.

Exercise 5

Unix Date Anomalies

All computer systems have date anomalies. Unix is expected to experience date problems in the year 2038.

Exercise 6

Do a calculation to estimate approximately how many seconds there are in the Unix life-time from 1 January 1970 to 1 January 2038 (ignore leap years)?

In the year 2038 the built-in variable used to keep time in Unix and similar operating systems will overflow. The maximum number of seconds that the Unix time variable can count is 2,147,483,647. This number of seconds will be reached on 19 January 2038 at 03:14:07.

Exercise 7

What power of 2 is 2,147,483,647 closest to (hint use your calculator and divide log 2,147,483,647 by log 2)?

Demonstration

The time stamp variable is 32 bits long. Only 31 of these bits are used to forward store the number of seconds. The maximum number of seconds the remaining 31 bits can accommodate is therefore:

230 + 229 + 228 + 227 ... + 23 + 22 + 21 + 20
=
230 + 230 – 1
=
2 * (230) – 1
=
231 – 1

Note: in the above calculation we have 31 bits but since we start at 20 we get to only 230

Exercise 8

Evaluate 231 – 1 using your calculator and determine that it is in-fact exactly the number of seconds in the Unix Lifetime (2,147,483,647)?

A solution to the Unix Date Problem

It has been suggested that the Unix date problem can be fixed by converting the Unix time stamp variable from a 32 bit variable to a 64 bit variable. In which case 63 bits would be used to forward count the number of seconds in the Unix lifetime.

Exercise 9

What is the maximum number of seconds that a 64 bit time stamp variable can accommodate before it overflows?

Ignoring leap years approximately how many years would be available in a 64 bit Unix lifetime?

Date Representations in Different Countries

In England and Australia dates are written in the format day/month/year, however in the United States, the format "month, day, year" is used.

A date in Australia of 04/08/1999 would be the fourth of August 1999. In the United States the same date would represent the eighth day of April 1999.

There is clearly large potential for dates to be misinterpreted when crossing national borders. Consider a Microsoft excel spreadsheets which contains a date written in Australia of 04/08/1999. If the computer was set up for Australia then the date would be fine but if the file is e-mailed to a computer reading US dates problems could result. This problem is resolved by actually storing dates in spreadsheets and other applications directly in terms of pure numbers. That way whenever a computer opens a file it just calculates the date based on the number in the date field.

A computer using United states date settings would present an Australian date correctly with respect to its date formatting since it would actually calculate what date to use based on the numerical value of the date field.

References

The Calendar. DE Duncan. Fourth Estate - London 1998.

The Penguin Dictionary of Physics. VH Pitt (Editor). Penguin 1987.

How Stuff Works
http://computer.howstuffworks.com/

The Next Millennium Headache
http://www.google.com.au/search?q=cache:LhHd8hXzJCwJ:www.wired.com/news/news/technology/story/14390.html+Unix+date+y2k&hl=en&ie=UTF-8

Computer World - DANGEROUS DATES FOR SOFTWARE APPLICATIONS
http://www.info2000.nb.ca/Information2000/wa-9806-dangerdates.htm Inline Image - Go To www.precisioninfo.com