Sue Alchesay - Data Structures for Date and Time Critical Structures
Posted September 1 1997
Sue Alchesay has a part time consulting business and works with a physicians group of hand surgeons and also works on emergency room software. In the process of creating applications for all of her customers she often has to determine how much time has elapsed or when the next time some action must be taken. To accomplish these tasks she has become very familiar with the date and time functions available from Clarion.
After writing an article for the now defunct Clarion Windows Journal about Clarion Dates, Sue approached TopSpeed about doing a seminar at DEVCON on the same subject. Clarion liked the idea but wanted to have her also discuss the Year 2000 problem and what it means to Clarion programmers.
Date and Time Considerations
Sue considers that several things are absolute necessities when using Dates & Times in your applications.
- Must be accurate
- Must be easy for users
- Must be able to calculate & manipulate for desired results
- Must work after December 31, 1999
The seminar covered the definitions of Clarion Standard Dates (CSD) and Clarion Standard Times CST), conventional calculations of Dates and Times, the technique that she uses for calculating time across dates and Date and Time tools sets available to Clarion programmers.
First of all, for you newbies<G>, dates and times are usually stored in a LONG variable. Doing this usually gives you the most flexibility when using dates and times, because all of the internal Clarion functions expect the Dates and Times to be in that format.
The CSD is stored as the number of days since December 28, 1800, but the only valid dates are those since January 1, 1801 which is CSD 4. The last valid CSD is 109,211 which is December 31, 2099. (In C4 the date range will be expanded to a much later time). One beneficial side effect of this date range is that you can use modulus arithmetic to determine what day of the week a date fell on. This means that if you divide any CSD by seven the remainder will tell you which day of the week the date fell on (0=Sunday, 1=Monday...).
There are 18 possible choices for displaying a CSD and an entry field does automatic conversion from any of the 18 choices to a CSD. There also are multiple options for separation characters available for use.
One new CSD ability is Intellidate. Intellidate allows you to assign a date range which pivots on the current date to determine when to rollover the Century. For example, by default the Intellidate uses a date range of 80/20. If a two digit year is entered and it is less than 80 years than the current year then the century will default to 1900. If a two digit year is more than 80 years ago or more than 20 years into the future then the century will default to 2000. This date range is adjustable by the programmer to use a date range appropriate for the date entry field.
Sue discussed several of the functions available to work with CSD.
- Date( month, day, year ) returns CSD
- Month( CSD ) returns month of year
- Date( CSD ) returns day of month
- Year( CSD ) returns 4-digit year
- AGE( birthdate, basedate ) returns 7-char string
- 1 - 60 days 'nn DAYS'
- 61 days to 24 months 'nn MOS'
- 2 years to 999 years 'nnn YRS'
- TODAY() returns CSD
- SETTODAY( CSD ) sets system date
Clarion Standard Times (CST) are based on the number of hundredths of a second since midnight, plus one. (Plus one so that an entry of zero can be interpreted as a NULL time or time not entered.) The range of valid CST values are 1 (which is equivalent to midnight) and 8,640,000 (which is equivalent to 23:59:59:99)
There are 8 different options of time formats to display a CST and the functions available to manipulate CST are:
- CLOCK() returns CST
- SETCLOCK() sets system time
Remember, since CST is measured in hundredths of a second
1 second is equal to 100
1 minute is equal to 6,000
1 hour is equal to 360,000
12:01AM is equal to 6,001 (midnight is equal to 1)
To calculate elapsed time a trick is available for you to use. Store the CSD and CST in a REAL variable with the CSD portion on the right of the decimal and dividing the CST by 8,640,000 and placing the result on the right side of the decimal. This will result in a variable that you can add or subtract to easily find the total elapsed time between two times without the fancy footwork of declaring temporary variables and nested IF structures to determine how many days have gone by. There should be a simple application on CIS soon that demonstrates this technique.
Three tools are available to help you with Date and Time calculations on CIS.
- DateTools from ProDomus, Inc 79.00 (860) 233-0705
- DAS_Tools from TinMan Dev Corp 99.00 (316) 942-6866
- Date & Time Tools & Templates FREE CIS Clarion lib
Year 2000 (Y2K) Considerations for Clarion Programmers.
There are three facets to consider when deciding if the Y2K will be a problem for you as a Clarion Programmer.
- Software
- Hardware
- Operating System
First, because you use Clarion and you use CSD (see above) you don't need to worry about the Y2K problem right? Well, if your using a display format that contains a 4-digit year you are correct. If not then ambiguities could creep in. Much more likely you will be affected by one of the other two area.
The hardware problem revolves around the fact that the CMOS Real Time Clock (RTC) in most PCs only store the date as YYMMDD format. The BIOS that comes with your computer is responsible for appending the century numbers to the CMOS RTC. The Operating System gets the year from the BIOS. Most software that runs gets the date from the Operating System but a few programs go directly to the BIOS for the Date.
For most Operating Systems (DOS, Win3x, Win95) the Y2K may change the date to Jan 1 1980 because the BIOS will return Jan 1, 1900 which fails the reasonableness test of the OS and results in the earliest date the OS finds reasonable. WinNT does not have this problem. It appears that Win98/9 will not have this problem.
To determine if your PC or PCs you are responsible for have this problem you can contact RightTime of Miami, FL (305) 644-6500 or http://www.rightime.com/year2000/year2000.txt. This company has a file TEST2000.ZIP that you can use to test to see if a patch will work on your machines. If the patch will work then a small fee per machine can patch your BIOS.
If you have an AWARD v 4.5x series BIOS then your BIOS will have to be replaced.
In summary there are a few things that you can do to check your machines:
Check your BIOS. If your BIOS has a problem:
- patch with software
- move to NT
- replace BIOS
- replace machine
- enter date every time you boot
Sue Alchesay gave a complete and informative review of Clarion Standard Dates and Times and an eye-opening look at potential hardware problems that Clarion Programmers should be on the lookout for when defending against the Y2K problem.
Article comments
Search ClarionMag
From the archives
A Callback Technique for Capesoft's FileManager2
12/21/2006 12:00:00 AM
CapeSoft's FileManager2, and its more recent incarnation FileManager3, are amazing products: they completely automate the process of upgrading client databases, whether local or across a network, and make it easy to do file maintenance. Randy Rogers shows how to add a callback procedure to FM2 to provide user feedback during startup.
