Return-Path: <dskhatri@MIT.EDU>
Received: from central-city-carrier-station.mit.edu by po11.mit.edu (8.9.2/4.7) id QAA12419; Tue, 9 Apr 2002 16:05:14 -0400 (EDT)
Received: from melbourne-city-street.mit.edu (MELBOURNE-CITY-STREET.MIT.EDU [18.7.21.86])
	by central-city-carrier-station.mit.edu (8.9.2/8.9.2) with ESMTP id QAA29375
	for <sipb@mit.edu>; Tue, 9 Apr 2002 16:04:44 -0400 (EDT)
Received: from khatri.mit.edu (KHATRI.MIT.EDU [18.247.4.23])
	by melbourne-city-street.mit.edu (8.9.2/8.9.2) with ESMTP id QAA29519
	for <sipb@mit.edu>; Tue, 9 Apr 2002 16:04:44 -0400 (EDT)
Message-Id: <5.0.2.1.2.20020409153744.01702120@hesiod>
X-Sender: dskhatri@hesiod (Unverified)
X-Mailer: QUALCOMM Windows Eudora Version 5.0.2
Date: Tue, 09 Apr 2002 16:04:44 -0400
To: sipb@mit.edu
From: Danish S Khatri <dskhatri@MIT.EDU>
Subject: Palm OS Question
Mime-Version: 1.0
Content-Type: multipart/alternative;
	boundary="=====================_1956653==_.ALT"

--=====================_1956653==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Dear SIPB Member,

I have been struggling with a palmos program for some time now and wondered 
if you could offer a solution.  In the program, I refer to a database and 
attempt to sort the records by the date.  Each record has the following 
structure (just the date part is the significant one as far as the question 
is concerned):

typedef struct{
   Word day :5;
   Word month :4;
   Word year :7;   //Year since 1904.. for example, for 2002 year=98
   Byte hour;
   Byte minute;
   ....
}MyRecord;

MyRecord * recordPtr;

So in referring to the records, I look at the day, month and year and 
compare it to the DateTimeType structure that holds the current time, which 
I derived from:

TimSecondsToDateTime(TimGetSeconds(),&Time);

However, when comparing the Time.day and recordPtr->day, they are not equal 
even when the day is the same (I am using Metrowerks CodeWarrior 6 for the 
Palm OS and using the debugger one can probe the values of the MyRecord and 
DateTimeType structures).  I used the following simple if statement to 
check equality:

if((Time.day)==recordPtr->day)
  { ....}

I thought that because the variable "day" in structure DateTimeType is 
defined as type Sword (char), and hence is 8 bits long, while "day"  in 
MyRecord is 5 bits long, one couldn't compare the two.  First question is, 
is there a way of converting the MyRecord "day" to 8 bits without losing 
information?  If you just use the type conversion below, the resulting 
value is not the same as the original.

Sword my_day=recordPtr->day;

I cannot do anything about the way MyRecord is defined.  I tried using a 
(palmos defined) DateType to store the current date, but it results in a 
false date:

//Structure of palmos defined DateType
typedef struct{
Word year :7; //years since 1904
Word month :4;
Word day :5;
}DateType;
typedef DateType * DatePtr;

//What I did to get date
DateType date;
DateSecondsToDate(TimGetSeconds(), &date);

If I can get the palmos defined function DateSecondsToDate() to work and 
store the real date, then comparison of the date.day and recordPtr->day 
would work because "day" in each case is of the same type, but again I'm 
stuck because DateSecondsToDate() doesn't work correctly.  The second 
question is why isn't a simple function like DateSecondsToDate() not 
working correctly?

Thank you for your help,

Danish Khatri



_____________________________

Danish S Khatri
MIT Class of 2004

410 Memorial Drive
Cambridge, MA 02139
USA

dskhatri@mit.edu
dskhatri@media.mit.edu
http://web.mit.edu/dskhatri/www
--=====================_1956653==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Dear SIPB Member,<br>
<br>
I have been struggling with a palmos program for some time now and
wondered if you could offer a solution.&nbsp; In the program, I refer to
a database and attempt to sort the records by the date.&nbsp; Each record
has the following structure (just the date part is the significant one as
far as the question is concerned):<br>
<br>
typedef struct{<br>
&nbsp; Word day :5;<br>
&nbsp; Word month :4;<br>
&nbsp; Word year :7;&nbsp;&nbsp; //Year since 1904.. for example, for
2002 year=98<br>
&nbsp; Byte hour;<br>
&nbsp; Byte minute;<br>
&nbsp; ....<br>
}MyRecord;<br>
<br>
MyRecord * recordPtr;<br>
<br>
So in referring to the records, I look at the day, month and year and
compare it to the DateTimeType structure that holds the current time,
which I derived from:<br>
<br>
TimSecondsToDateTime(TimGetSeconds(),&amp;Time);<br>
<br>
However, when comparing the Time.day and recordPtr-&gt;day, they are not
equal even when the day is the same (I am using Metrowerks CodeWarrior 6
for the Palm OS and using the debugger one can probe the values of the
MyRecord and DateTimeType structures).&nbsp; I used the following simple
if statement to check equality:<br>
<br>
if((Time.day)==recordPtr-&gt;day)<br>
&nbsp;{ ....}<br>
<br>
I thought that because the variable &quot;day&quot; in structure
DateTimeType is defined as type Sword (char), and hence is 8 bits long,
while &quot;day&quot;&nbsp; in MyRecord is 5 bits long, one couldn't
compare the two.&nbsp; First question is, is there a way of converting
the MyRecord &quot;day&quot; to 8 bits without losing information?&nbsp;
If you just use the type conversion below, the resulting value is not the
same as the original.&nbsp; <br>
<br>
Sword my_day=recordPtr-&gt;day;<br>
<br>
I cannot do anything about the way MyRecord is defined.&nbsp; I tried
using a (palmos defined) DateType to store the current date, but it
results in a false date:<br>
<br>
<font face="Courier, Courier">//Structure of palmos defined 
DateType<br>
typedef struct{<br>
Word year :7; //years since 1904<br>
Word month :4;<br>
Word day :5;<br>
<b>}</b>DateType;<br>
typedef DateType * DatePtr;<br>
<br>
</font>//What I did to get date<br>
DateType date;<br>
DateSecondsToDate(TimGetSeconds(), &amp;date);<br>
<br>
If I can get the palmos defined function DateSecondsToDate() to work and
store the real date, then comparison of the date.day and
recordPtr-&gt;day would work because &quot;day&quot; in each case is of
the same type, but again I'm stuck because DateSecondsToDate() doesn't
work correctly.&nbsp; The second question is why isn't a simple function
like DateSecondsToDate() not working correctly?&nbsp; <br>
<br>
Thank you for your help,<br>
<br>
Danish Khatri<br>
<br>
<br>
<x-sigsep><p></x-sigsep>
_____________________________<br>
<br>
<font color="#0000FF"><b><i>Danish S Khatri<br>
</font>MIT Class of 2004<br>
<br>
410 Memorial Drive<br>
Cambridge, MA 02139<br>
USA<br>
<br>
dskhatri@mit.edu<br>
dskhatri@media.mit.edu<br>
<a href="http://web.mit.edu/dskhatri/www" eudora="autourl">http://web.mit.edu/dskhatri/www</a></b></i></html>

--=====================_1956653==_.ALT--

