Hi, 

I was following the quite interesting Y2K bug thread, and decided to 
look around myself. Here is what I found:

typedef struct {
        SWord second;
        SWord minute;
        SWord hour;
        SWord day;
        SWord month;
        SWord year;
        SWord weekDay;          // Days since Sunday (0 to 6)
        } DateTimeType;

The year is a whole WORD (16 bit), not bad. But, if we want to store 
the date in database, we might only save day, month and year in the 
DB to save space (can even pack them in 4 bytes). Then use a function 
to convert values to the DateTimeType. All we need is some functions 
to do our date calculations. Well...

void DateAdjust (DatePtr dateP, Long adjustment)

Not much use with DateTimeType, but we have

void TimAdjust (DateTimePtr dateTimeP, Long adjustment)

Good, but we have to convert the adjustment to seconds. Small price 
to run my program on 2031+ :). Let's see  more...


void DateToAscii (Byte months, Byte days,
Word years, DateFormatType dateFormat,
CharPtr pString)

void DateToDOWDMFormat (Byte months, Byte days,
Word years, DateFormatType dateFormat,
CharPtr pString)

UInt DayOfMonth (UInt month, UInt day, UInt year)

UInt DayOfWeek (UInt month, UInt day, UInt year)

UInt DaysInMonth (UInt month, UInt year)

ULong TimDateTimeToSeconds (DateTimePtr dateTimeP)

ULong TimGetSeconds (void)

void TimSecondsToDateTime (ULong seconds,
DateTimePtr dateTimeP)

All of the above functions seems to work with WORD length year. 
Excellent!

void DateDaysToDate (ULong days, DatePtr dateP)
void DateSecondsToDate (ULong seconds,DatePtr dateP)
ULong DateToDays (DateType date)

The above 3 are only exceptions. They need the poor DateType. Can we 
do without them?

DateDaysToDate : This one converts days since 1/1/1904 to date. We 
can set up a DateTime type to 1/1/1904 or whatever we like, and use 
TimAdjust to get the same functionality. Probably more flexible.

DateSecondsToDate: Could use TimSecondsToDateTime.

DateToDays: Given a date returns days since 1/1/1904. There seems to 
be no direct replacement. We can use TimDateTimeToSeconds get the 
seconds since 1/1/1904, and use a function to convert it to days. By 
the way TimDateTimeToSeconds returns a ULong, so it's good for 
approx. 136 years. That is 2040. Here we go again!!! TimeGetSeconds 
also has the same problem.

It would be definitely help to have a function, which takes two 
DateTimeType and returns the difference in seconds. Something like VB 
DateDiff function shall be great. 

It seems someone in the Palm OS design team probably thought ahead 
and provided the DateTime type. They were almost there, but not 
quite. A program that reads the system time shall fail after 2040. 
this anyway cannot be avoided, if the OS is keeping the real time in 
an ULong. By the way, my Palm III don't allow me to set a date later 
than Dec 31, 2031. 

Everything said, it seems to me, for most cases we can write a 
program which can run on 2031+, using existing API. Of course, it 
can't use the system date and we have to roll our own date input 
routine (most of us do). 

Now, all I need to do is to test. How do I set the date in my Palm to 
2041? ;)

Just my 0.2 cents!

-Sugho-




______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to