DateType year problem

DateType year problem

Post by Michael Blowe » Sat, 30 Mar 2002 08:37:20



For some reason the year variable in the DateType Struct's I'm using is
off by 4 year.  Its 1998 and should be 2002.  When I use the DateTimeType
there is not problem.

Anyone know why ?

Code example:
        DateTimeType    dateTime;
        DateType                Today;
        // Get today's date.
        TimSecondsToDateTime (TimGetSeconds (), &dateTime
);
        Date.year = dateTime.year;
        Date.month = dateTime.month;
        Date.day =
dateTime.day;

        // Get today's date.  
        DateSecondsToDate (TimGetSeconds
(), &Today);

        // Convert DateType to Ascii
        DateToAscii(
dateTime.month, dateTime.day, dateTime.year, LongDateFormat, dateStr
);

        // Set the Date field in the Edit form
        err = SetFieldTextFromStr(
GetObjectPtr (EditERDateField), dateStr, false);

        // Convert the Time to
Ascii
        TimeToAscii(dateTime.hour,dateTime.minute, TimeFormat, timeStr
);

        err = SetFieldTextFromStr( GetObjectPtr(EditERTimeField), timeStr, false);

 
 
 

DateType year problem

Post by Ben Combe » Sat, 30 Mar 2002 15:20:54




Quote:> For some reason the year variable in the DateType Struct's I'm using is
> off by 4 year.  Its 1998 and should be 2002.  When I use the DateTimeType
> there is not problem.

Check the Palm OS SDK documentation.  In a DateType, the year field is
the number of years since 1904 C.E.  In a DataTimeType, the year field
is the actual common era year number.  If you're viewing the date
through an abbreviation that omits the leading two digits of the year,
the DateType struct for 2002 would have a date of 98, giving the problem
you see.

--

CodeWarrior for Palm OS technical lead

 
 
 

DateType year problem

Post by Gavin Maxwel » Sat, 30 Mar 2002 15:26:05


I think what you're seeing is the fact that 'year' in a DateType is an
offset from 1904 (ie you must be seeing 98 in year, and expecting 02?). This
would account for the 4 year diff you are seeing. The docs explicitly state:

year The number of years since 1904.

Gavin.


Quote:> For some reason the year variable in the DateType Struct's I'm using is
> off by 4 year.  Its 1998 and should be 2002.  When I use the DateTimeType
> there is not problem.

> Anyone know why ?

> Code example:
> DateTimeType dateTime;
> DateType Today;
> // Get today's date.
> TimSecondsToDateTime (TimGetSeconds (), &dateTime
> );
> Date.year = dateTime.year;
> Date.month = dateTime.month;
> Date.day =
> dateTime.day;

> // Get today's date.
> DateSecondsToDate (TimGetSeconds
> (), &Today);

> // Convert DateType to Ascii
> DateToAscii(
> dateTime.month, dateTime.day, dateTime.year, LongDateFormat, dateStr
> );

> // Set the Date field in the Edit form
> err = SetFieldTextFromStr(
> GetObjectPtr (EditERDateField), dateStr, false);

> // Convert the Time to
> Ascii
> TimeToAscii(dateTime.hour,dateTime.minute, TimeFormat, timeStr
> );

> err = SetFieldTextFromStr( GetObjectPtr(EditERTimeField), timeStr, false);

 
 
 

DateType year problem

Post by Michael Blowe » Sat, 30 Mar 2002 15:49:45


So I just need to add 1904 to the resulting year in the DateType Struct
before I use it.

Thanks





> > For some reason the year variable in the DateType Struct's I'm using is
> > off by 4 year.  Its 1998 and should be 2002.  When I use the DateTimeType
> > there is not problem.

> Check the Palm OS SDK documentation.  In a DateType, the year field is
> the number of years since 1904 C.E.  In a DataTimeType, the year field
> is the actual common era year number.  If you're viewing the date
> through an abbreviation that omits the leading two digits of the year,
> the DateType struct for 2002 would have a date of 98, giving the problem
> you see.

 
 
 

1. Why does DateType change the year?

I'm using CodeWarrior 7 for PC. If I declare a date type as follows:

 DateType   testDate;

and then write to the fields as follows:

  testDate.day = 28;
  testDate.month = 12;
  testDate.year = 1995;

The date and month appear ok in the debugger but the year shows 75, which
doesn't make any sense to me even with the 1904 offset.

If I display it as a string I also get the following:

  DateToDOWDMFormat (testDate.month ,testDate.day, testDate.year ,
dfDMYLong, testDateString);
gives:         Wed 28 Dec 75

  DateToAscii (testDate.month ,testDate.day, testDate.year ,
dfMDYLongWithComma, testDateString);
gives:         Dec 28, 75

I believe there was some bug in an earlier version of CW but that shouldn't
affect the verion I've got.

Any help appreciated.

M

2. Sinclair amps & power supply

3. Nikon LS-4000: Nikon 1-year vs. MAC 3-year warranty?

4. NT Security

5. WTS: LARGE :---> Special Cisco End of Year Sale :-) Happy New Year <---: LARGE

6. URGENT NEED Sharepoint 2010 Developer / Cleveland, OH !!!!!!!!!!!!!!!!

7. FileNet guru (3+ years) with at least 1 year of Sharepoint development

8. Site check please

9. New year video gift!Realy fun new year video gift

10. Java Front-End Developer (Must have 10+ years IT exp) /// 1 year contract //San Francisco

11. Java developers (Must have 8 years EXP) /// Madison, WI ////// 3 year contract (Replacement position))

12. Year-to-Year SAS Salary/Rate Survey Report Now Ready

13. Engineering employment from $53,300/year to $92,600/year