Subj : not ignoring you... but... To : mark lewis From : Bj”rn Felten Date : Sat Jul 10 2004 07:12 pm ml> i found the unix2norm routine... its not anything like ml> the stuff i use... Here's one that I (and several others) have used for more than ten years now. Take it or leave it. :) - = * = - unit UnixUtil; { By Bj”rn Felten @ 2:203/208. No rights reserved what so ever... :) } INTERFACE uses dos; function GetTimeZone: shortint; function IsLeapYear(Source: word): boolean; function Norm2Unix(var DT: datetime): longint; procedure Unix2Norm(Date: longint; var DT: datetime); function D1970(var DT: datetime): longint; IMPLEMENTATION const DaysPerMonth : array[1..12] of shortint = (31,28,31,30,31,30,31,31,30,31,30,31); SecsPerMinute : longint = 60; SecsPerHour : longint = 60 * 60; SecsPerDay : longint = 60 * 60 * 24; SecsPerYear : longint = 60 * 60 * 24 * 365; SecsPerLeapYear : longint = 60 * 60 * 24 * 366; function GetTimeZone; var Environment : string; I, E : integer; begin I := 0; {Assume UTC} Environment := getenv('TZ'); {Grab TZ string} if Environment<>'' then begin delete(Environment,1,3); val(Environment,I,E); if E>0 then begin delete(Environment,1,E); for E := 1 to length(Environment) do Environment[E] := Upcase(Environment[E]); if pos('DT',Environment)>0 then inc(I) end end; GetTimeZone := I end; function IsLeapYear; begin IsLeapYear := (Source and 3 = 0) end; function D1970; { Thanks to Paul Schlyter... } begin with DT do D1970 := longint(367) * Year - 7 * (Year + (Month + 9) div 12) div 4 + 275 * Month div 9 + Day - 719574 end; function Norm2Unix; var UnixDate : longint; begin UnixDate := D1970(DT) * SecsPerDay; {days since 1970} with DT do begin inc(UnixDate,(SecsPerHour * Hour)); {add hours} inc(UnixDate,(SecsPerMinute * Min)); {add minutes} inc(UnixDate,Sec); {add seconds} UnixDate := UnixDate + (GetTimeZone * SecsPerHour) {add UTC offset} end; { with Date do } Norm2Unix := UnixDate end; procedure Unix2Norm; var SecsToLose, LocalDate: longint; procedure Split(var A: word; B: longint); begin A := LocalDate div B; LocalDate := LocalDate mod B end; begin with DT do begin Year := 1970; Month := 1; LocalDate := Date - (GetTimeZone * SecsPerHour); {Local time date} { sweep out the years } SecsToLose := SecsPerYear; while LocalDate >= SecsToLose do begin inc(Year,1); dec(LocalDate,SecsToLose); if IsLeapYear(Year) then SecsToLose := SecsPerLeapYear else SecsToLose := SecsPerYear end; { and now the months } Split(Day,SecsPerDay); if IsLeapYear(Year) then DaysPerMonth[02] := 29 else DaysPerMonth[02] := 28; {Check for Feb. 29th} while Day >= DaysPerMonth[Month] do begin dec(Day,DaysPerMonth[Month]); inc(Month,1) end; { the rest is a piece of cake } inc(Day); Split(Hour,SecsPerHour); Split(Min,SecsPerMinute); Sec := LocalDate end { with DT do } end; { procedure UnixToNorm } end. { unit UnixTime } --- * Origin: -=P=I=X=- / Psion Info Xchange (+46-31-960447) (2:203/208) .