home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,420 of 2,978   
   Jochen to All   
   Re: Packed Date problem   
   21 Mar 07 16:04:25   
   
   From: jotel99@hotmail.com   
      
   Marco van de Voort typed:   
   > On 2007-03-21, mljdth  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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca