Page 1 of 1

PostPosted: Mon Mar 22, 2004 11:20 am
by Ralpf
Since PocketC 6.5.1 you can open a date selection dialog. The initial date for this dialog has to be specified by secs which is the number of seconds since Jan 1, 1904 minus 2^31.
My question is how to change a given date to the secs format. I could`nt find a way for it.

PostPosted: Mon Mar 22, 2004 10:43 pm
by Vigon
The answer may be here:
but there is a little work to do...

PostPosted: Tue Mar 23, 2004 2:26 am
by Vigon
Code: Select all
Just an Idea:
Using a binary approximation,
begining in the year 1967 ,the middle of the range 1904-2031 (46751 days) (4039286400 secs) of the Palm OS.
and using the secs parameter of datex() as the approximation variable.
int DateToSeconds(int Y, int M, int D){
   int i,targetdate,datefinder,offset;
   targetdate= Y*10000 + M*100 + D ;   //(year*10000+month*100+day)
   datefinder= 2019643200-2147483648;   // seconds (from 1904 to 1967 and 6 months) minus 2^31
   offset=2019643200;               //aprox. seconds in 63.5 years (Half range)(23192 days)
      else datefinder=datefinder+offset;
   if(datex(datefinder,0)==targetdate)return datefinder;
   if(datex(datefinder,0)>targetdate)return (datefinder-86400);   //adjust
   if(datex(datefinder,0)<targetdate)return (datefinder+86400);   //adjust
selectdate(DateToSeconds(1999,12,31), 0, "DateToSeconds Working!"); //an example

PostPosted: Tue Mar 23, 2004 2:43 am
by dewey
Thanks for providing code for this. In the next version, I will expose a function to do this directly.

PostPosted: Tue Jul 13, 2004 2:14 pm
by Vilmos
Is it just me or does this sample always show you Jan 1, 1968? I tried random dates between today and 2010!

back to the drawing board I guess.


PostPosted: Tue Jul 13, 2004 8:06 pm
by Vigon
Hi Vilmos, after your comments I tried several dates in the range and
the procedure was working OK.
I'll apreciate an example with the problem.

I used:

selectdate(DateToSeconds(2004,10,31), 0, "DateToSeconds Working!");
selectdate(DateToSeconds(2008,6,15), 0, "DateToSeconds Working!");
selectdate(DateToSeconds(2007,2,22), 0, "DateToSeconds Working!");
selectdate(DateToSeconds(2010,11,1), 0, "DateToSeconds Working!");


PostPosted: Tue Jul 13, 2004 8:42 pm
by Vilmos
The two dates I know for sure that I used are 2004/06/30 and today 2004/07/13.

I had just copied and pasted the post into a memo then compiled it on the palm. I had to put line breaks in but otherwise didn't modify anything on purpose but the dates.

I've solved my problem by using OnBoardC and the built-in Palm functions to resolve seconds to day. PocketC was slowing me down when I simply wanted a tiny calculator to show me what the max mileage can be for today on my car lease.


PostPosted: Tue Jul 13, 2004 8:56 pm
by Vigon
I tried both and are working ok.
In the PocketC Desktop Editor with PalmOS Simulator on my PC and
in my handheld....

selectdate(DateToSeconds(2004,06,30), 0, "DateToSeconds Working!");
selectdate(DateToSeconds(2004,07,13), 0, "DateToSeconds Working!");

May be we're missing something!!

PostPosted: Tue Jul 13, 2004 9:29 pm
by Vilmos
You are completely right. It works fine in PocketC Desktop. something happened when I pasted it into the Palm Desktop in a memo and then tried to compile it on the Palm.

I know the problem was that the memo was pasted as one long line which will not compile because there are comments within it. I'm sure that a comment ended up taking some code with it. You just can't tell on the Palm itself.

Ok I'll use that next time then. :)