Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Borland > Re: Packed Date...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 1010 of 1114
Post > Topic >>

Re: Packed Date problem

by "Jochen" <jotel99@[EMAIL PROTECTED] > Mar 21, 2007 at 04:04 PM

Marco van de Voort typed:
> On 2007-03-21, mljdth <mljdtj@[EMAIL PROTECTED]
> wrote:
>>
>> I'm trying to extract data from a file generated by an old Turbo
>> Pascal program. (Not sure which version exactly)..
>> Using a hex editor, I have determined that the dates are 2 bytes in
>> length.. Some examples are:
>>
>> EA40 = 59968 = 7/1/06
>> EB40 = 60224 = 7/2/06
>> 5E41 = 24129 = 10/25/06
>> 7241 = 29429 = 11/14/06
>>
>> I cannot determine how the dates are encoded.. Any suggestions?
>
> They are written as a word, so your notation is byteswapped. It is
> probably $40EA,$40EB,$415E,$4172 etc.
>
> And that looks awfully like simply days after a date (1/1/1960 or
> maybe the authors birthday).

hehe marco.
it is 1.1.1960! :)


- - TP Code - -

program packed_date;

const
  ANZ = 4;
  d: array[1 .. ANZ] of word = ($40EA, $40EB, $415E, $4172);

var
  i: word;


function todatestring(w: word): string;

  function daysinyear(y: word): word;
  begin
   if (y mod 4) = 0 then
     if (y mod 400) = 0 then daysinyear := 366
     else
      if (y mod 100) = 0 then daysinyear := 365
      else daysinyear := 366
   else daysinyear := 365
  end;

  function daysinmonth(y,m: word): word;
  const dm : array [1..12] of word =
(31,28,31,30,31,30,31,31,30,31,30,31);
  begin
    if m = 2 then
      if daysinyear(y) = 366 then daysinmonth := 29
      else daysinmonth := 28
    else daysinmonth := dm[m];
  end;

  function w2str(w: word): string;
  var s: string;
  begin
   str(w, s);
   w2str := s;
  end;

var y,m: word;
begin
  y := 1960;
  m := 1;
  while w>daysinyear(y) do
  begin
    dec(w, daysinyear(y));
    inc(y);
  end;
  while w>daysinmonth(y,m) do
  begin
    dec(w, daysinmonth(y,m));
    inc(m);
  end;
  todatestring := w2str(y) + '-' + w2str(m) + '-' + w2str(w);
end;

begin
 for i:=1 to ANZ do writeln(i:3, d[i]:8, todatestring(d[i]):12);
 write('Enter');
 readln
end.

- - -

but i would give it a few tests more with some other dates maybe ;)

hth
jo

-- 
http://radio789.net.ms
- Radio 789 - We play it ALL
Radiostream: http://stream789.net.ms
 




 6 Posts in Topic:
Packed Date problem
"mljdth" <ml  2007-03-21 06:42:36 
Re: Packed Date problem
Marco van de Voort <ma  2007-03-21 14:35:04 
Re: Packed Date problem
"Jochen" <jo  2007-03-21 16:04:25 
Re: Packed Date problem
"Jochen" <jo  2007-03-21 16:13:00 
Re: Packed Date problem
"mljdth" <ml  2007-03-21 14:53:38 
Re: Packed Date problem
Dr J R Stockton <jrs@[  2007-03-21 23:49:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 2:45:37 CDT 2008.